In [1]:
import zipfile
%matplotlib inline
import numpy as np
import ast
import json
import urllib
import urllib2
from cStringIO import StringIO
import pandas as pd
import requests
import os
import geopandas as gpd
import matplotlib.pylab as pl
from fiona.crs import from_epsg
import fiona
import matplotlib.pylab as pl
from matplotlib import colors
import shapely
import seaborn as sns
from sklearn.cluster import KMeans
#add necessary libraries
import networkx as nx #library supporting networks
from shapely.geometry import Point, Polygon

In [2]:
import shapely as shp
#import pandas as pd, numpy as np, matplotlib.pyplot as plt
from sklearn.cluster import DBSCAN
from geopy.distance import great_circle
from shapely.geometry import MultiPoint
#import geopandas as gpd
#import seaborn as sns
#import requests
#import os
#import json
#import urllib
#import urllib2
from time import sleep
import imageio

In [3]:
from descartes import PolygonPatch
fname = 'Data/tracks_listing_households.geojson'
tracks = gpd.GeoDataFrame.from_file(fname)
print tracks.crs
totalshape = tracks.geometry[1]
for shape in tracks.geometry:
    totalshape = totalshape.union(shape)
totalshape
un = totalshape.envelope.symmetric_difference(totalshape)
un


{}
Out[3]:

In [4]:
#fileUrl = 'https://data.cityofnewyork.us/api/geospatial/arq3-7z49?method=export&format=GeoJSON'
#filebuffer = urllib.urlretrieve(fileUrl, filename='Subway Stations.geojson')
fname = 'Subway Stations.geojson'
print (fname)
subStations = gpd.GeoDataFrame.from_file('Subway Stations.geojson')
#subStations = subStations[subStations.line=='L']
subStations.crs = from_epsg(4326)


Subway Stations.geojson

In [5]:
subStations.shape


Out[5]:
(473, 6)

In [6]:
subStations.loc[subStations.name.duplicated(False)==True].name = subStations.loc[subStations.name.duplicated(False)==True].name + subStations.loc[subStations.name.duplicated(False)==True].line


C:\Users\ferna\Anaconda2\lib\site-packages\pandas\core\generic.py:2701: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self[name] = value

In [7]:
print len(subStations.loc[subStations.name.duplicated(False)==True])
subStations.loc[subStations.name.duplicated(False)==True].head(3)


197
Out[7]:
geometry line name notes objectid url
1 POINT (-74.00019299927328 40.71880300107709) 4-6-6 Express Canal St 4 nights, 6-all times, 6 Express-weekdays AM s... 2 http://web.mta.info/nyct/service/
2 POINT (-73.98384899986625 40.76172799961419) 1-2 50th St 1-all times, 2-nights 3 http://web.mta.info/nyct/service/
3 POINT (-73.97499915116808 40.68086213682956) 2-3-4 Bergen St 4-nights, 3-all other times, 2-all times 4 http://web.mta.info/nyct/service/

In [8]:
subStations.loc[30,'name']


Out[8]:
u'Grand Central - 42nd St'

In [9]:
subStations['nameduplicated'] = subStations.name.duplicated(False)
subStations['namemod'] = np.nan
for i in range(len(subStations)):
    if subStations.loc[i,'nameduplicated'] == True:
        subStations.loc[i,'namemod'] = subStations.loc[i,'name'] + ' - ' + subStations.loc[i,'line'].replace(' Express','')
    else:
        subStations.loc[i,'namemod'] = subStations.loc[i,'name']

In [10]:
subStations = subStations.drop([442,441,383,382,145])
subStations.reset_index(inplace=True)
subStations.shape


Out[10]:
(468, 9)

In [11]:
subStations.head(3)


Out[11]:
index geometry line name notes objectid url nameduplicated namemod
0 0 POINT (-73.99106999861967 40.73005400028978) 4-6-6 Express Astor Pl 4 nights, 6-all times, 6 Express-weekdays AM s... 1 http://web.mta.info/nyct/service/ False Astor Pl
1 1 POINT (-74.00019299927328 40.71880300107709) 4-6-6 Express Canal St 4 nights, 6-all times, 6 Express-weekdays AM s... 2 http://web.mta.info/nyct/service/ True Canal St - 4-6-6
2 2 POINT (-73.98384899986625 40.76172799961419) 1-2 50th St 1-all times, 2-nights 3 http://web.mta.info/nyct/service/ True 50th St - 1-2

In [12]:
for i in subStations.line:
    print i.replace(' Express','').split('-')
    print map(lambda x: x,i.replace(' Express','').split('-'))
    break


[u'4', u'6', u'6']
[u'4', u'6', u'6']

In [13]:
G=nx.Graph()
G.add_nodes_from(subStations.namemod)

In [14]:
def getXY(pt):
    return (pt.x, pt.y)

In [15]:
stationpos={}
subStations['longlat']= subStations.geometry.map(getXY)
for station in subStations.index:
    stationpos[subStations.namemod[station]]=subStations['longlat'][station]

In [16]:
len(stationpos)


Out[16]:
468

In [17]:
fname = 'CensusTracks.geojson'
tracks = gpd.GeoDataFrame.from_file(fname)
print tracks.crs 
tracks.head(3)


{}
Out[17]:
boro_code boro_ct_2010 boro_name cdeligibil ct_2010 ctlabel geometry ntacode ntaname puma shape_area shape_leng
0 5 5000900 Staten Island I 000900 9 (POLYGON ((-74.07920577013245 40.6434307837456... SI22 West New Brighton-New Brighton-St. George 3903 2497009.69813 7729.01679376
1 1 1009800 Manhattan I 009800 98 (POLYGON ((-73.96432543478758 40.7563815309909... MN19 Turtle Bay-East Midtown 3808 1906016.35002 5534.19981063
2 1 1010000 Manhattan I 010000 100 (POLYGON ((-73.96802436915851 40.7595781400528... MN19 Turtle Bay-East Midtown 3808 1860938.37721 5692.16873705

In [18]:
f, ax = pl.subplots(figsize=(15,12))

tracks.plot(c = 'k', linewidth = .5, ax = ax,  color= 'Blue')
pl.axis('off')

nx.draw(G,pos=stationpos,with_labels=False,arrows=True,node_size=15,style='dotted',edge_color='green')
pl.title("NYC Subway Stations", size=20)


Out[18]:
<matplotlib.text.Text at 0x1596d668>

In [19]:
for i in subStations.line:
    print i.replace(' Express','').split('-')
    print map(lambda x: x,i.replace(' Express','').split('-'))
    break


[u'4', u'6', u'6']
[u'4', u'6', u'6']

In [20]:
def getclosest(name):
    mask=[]
    for lines in subStations.line:
        if name in lines:
            mask.append(True)
        else:
            mask.append(False)
    distmat=np.empty((len(subStations[mask]),), dtype=float)
    print distmat.shape
    for stations in subStations[mask]['geometry']:
        distances=[]
        for other in subStations[mask]['geometry']:
            distances.append(stations.distance(other))
        #print len(distances)
        distmat = np.vstack((distmat,np.array(distances)))
    distmat = np.delete(distmat, 0, 0)
    print distmat.shape
    distmat
    for i in range(len(subStations[mask])):
        np.sort(distmat[i],kind='quicksort')[1]
        np.where( distmat[i] == np.sort(distmat[i],kind='quicksort')[1])[0][0]
        print subStations[mask].iloc[i]['namemod'], ',',str(subStations[mask].iloc[np.where( distmat[i] == np.sort(distmat[i],kind='quicksort')[1])[0][0]]['namemod'])

In [21]:
getclosest('L')


(19L,)
(19L, 19L)
Lorimer St - L , Graham Ave
Sutter Ave , Livonia Ave
Wilson Ave , Bushwick - Aberdeen
Grand St - L , Montrose Ave
Graham Ave , Grand St - L
Bedford Ave , Lorimer St - L
Montrose Ave , Grand St - L
Atlantic Ave , Broadway Junction - L
Halsey St - L , Wilson Ave
Myrtle - Wyckoff Aves - L , Halsey St - L
Livonia Ave , Sutter Ave
Canarsie - Rockaway Pkwy , E 105th St
E 105th St , Canarsie - Rockaway Pkwy
New Lots Ave - L , Livonia Ave
DeKalb Ave - L , Jefferson St
Bushwick - Aberdeen , Broadway Junction - L
Broadway Junction - L , Atlantic Ave
Jefferson St , DeKalb Ave - L
Morgan Ave , Montrose Ave

RUSHhourLinks=[ ('149th St - Grand Concourse - 4','125th St - 4-5-6-6'),###4 ("E 180th St","3rd Ave - 149th St"),##5 ('Nereid Ave (238 St)','233rd St'), ('233rd St','225th St'), ('225th St','219th St'), ('219th St','Gun Hill Rd - 2-5'), ('Gun Hill Rd - 2-5','Burke Ave'), ('Burke Ave','Allerton Ave'), ('Allerton Ave','Pelham Pkwy - 2-5'), ('Pelham Pkwy - 2-5','Bronx Park East'), ('Bronx Park East','E 180th St'), ###5 ('Parkchester','Hunts Point Ave'),###6 ('Hunts Point Ave','3rd Ave - 138th St'),###6 ('Fordham Rd - B-D','Tremont Ave'),###D ('Tremont Ave','145th St - A-B-C-D')###D ]

LateNightLinks=[ ('Grand St - B-D','DeKalb Ave - B-D-N-Q-R'),###D ('DeKalb Ave - B-D-N-Q-R',"Atlantic Av - Barclay's Center - D-N-Q-R"),###D ("Atlantic Av - Barclay's Center - D-N-Q-R",'Union St'),###D ('Union St','4th Av - 9th St - D-N-R'),###D ('4th Av - 9th St - D-N-R','Prospect Ave - D-N-R'),###D ('Prospect Ave - D-N-R','25th St'),###D ('25th St','36th St - D-N-R'),###D ('',''), ('',''), ('',''), ('',''), ('',''), ('','') ]


In [22]:
getclosest('7')


(22L,)
(22L, 22L)
Mets - Willets Point , 111th St - 7
Junction Blvd , 103rd St - Corona Plaza
Flushing - Main St , Mets - Willets Point
Woodside - 61st St , 69th St
Court Sq , Hunters Point Ave
Hunters Point Ave , Vernon Blvd - Jackson Ave
Vernon Blvd - Jackson Ave , Hunters Point Ave
Queensboro Plz , Court Sq
103rd St - Corona Plaza , Junction Blvd
111th St - 7 , 103rd St - Corona Plaza
Times Sq - 42nd St - 7-7 , 5th Ave - Bryant Pk
Grand Central - 42nd St - 7-7 , 5th Ave - Bryant Pk
69th St , 74th St - Broadway
74th St - Broadway , 69th St
52nd St , 46th St - 7
46th St - 7 , 40th St
82nd St - Jackson Hts , 90th St - Elmhurst Av
90th St - Elmhurst Av , 82nd St - Jackson Hts
33rd St - 7 , 40th St
40th St , 46th St - 7
5th Ave - Bryant Pk , Times Sq - 42nd St - 7-7
34th St - Hudson Yards , Times Sq - 42nd St - 7-7

In [23]:
sublines = ['G','N','R','Q','W','B','M','D','F','A','C','E','S','7','1','2','3','J','Z','L','4','5','6']

In [24]:
sublines.sort()
print sublines


['1', '2', '3', '4', '5', '6', '7', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'J', 'L', 'M', 'N', 'Q', 'R', 'S', 'W', 'Z']

In [25]:
Edges1=[
    ('Van Cortlandt Park - 242nd St','238th St'),
    ('238th St','231st St'),
    ('231st St','Marble Hill - 225th St'),
    ('Marble Hill - 225th St','215th St'),
    ('215th St','207th St'),
    ('207th St','Dyckman St - 1'),
    ('Dyckman St - 1','191st St'),
    ('191st St','181st St - 1'),
    ('181st St - 1','168th St - 1'),
    ('168th St - 1','157th St'),
    ('157th St','145th St - 1'),
    ('145th St - 1','137th St - City College'),
    ('137th St - City College','125th St - 1'),
    ('125th St - 1','116th St - Columbia University'),
    ('116th St - Columbia University','Cathedral Pkwy (110th St) - 1'),
    ('Cathedral Pkwy (110th St) - 1','103rd St - 1'),
    ('103rd St - 1','96th St - 1-2-3'),
    ('96th St - 1-2-3','86th St - 1-2'),
    ('86th St - 1-2','79th St - 1-2'),
    ('79th St - 1-2','72nd St - 1-2-3'),
    ('72nd St - 1-2-3','66th St - Lincoln Ctr'),
    ('66th St - Lincoln Ctr','59th St - Columbus Circle - 1-2'),
    ('59th St - Columbus Circle - 1-2','50th St - 1-2'),
    ('50th St - 1-2','Times Sq - 42nd St - 1-2-3'),
    ('Times Sq - 42nd St - 1-2-3','34th St - Penn Station - 1-2-3'),
    ('34th St - Penn Station - 1-2-3','28th St - 1-2'),
    ('28th St - 1-2','23rd St - 1-2'),
    ('23rd St - 1-2','18th St'),
    ('18th St','14th St - 1-2-3'),
    ('14th St - 1-2-3','Christopher St - Sheridan Sq'),
    ('Christopher St - Sheridan Sq','Houston St'),
    ('Houston St','Canal St - 1-2'),
    ('Canal St - 1-2','Franklin St'),
    ('Franklin St','Chambers St - 1-2-3'),
    ('Chambers St - 1-2-3','Rector St - 1'),
    #('Chambers St - 1-2-3','Cortlandt St - 1'), destroyed in 9/11
    #('Cortlandt St - 1','Rector St - 1'), destroyed in 9/11
    ('Rector St - 1','South Ferry')#ONLY THE FIRST 5 CARS CAN GET OFF AT SOUTH FERRY STATION
    ]

In [26]:
Edges2=[
    ('Wakefield - 241st St','Nereid Ave (238 St)'),
    ('Nereid Ave (238 St)','233rd St'),
    ('233rd St','225th St'),
    ('225th St','219th St'),
    ('219th St','Gun Hill Rd - 2-5'),
    ('Gun Hill Rd - 2-5','Burke Ave'),
    ('Burke Ave','Allerton Ave'),
    ('Allerton Ave','Pelham Pkwy - 2-5'),
    ('Pelham Pkwy - 2-5','Bronx Park East'),
    ('Bronx Park East','E 180th St'),
    ('E 180th St','West Farms Sq - E Tremont Av'),
    ('West Farms Sq - E Tremont Av','174th St'),
    ('174th St','Freeman St'),
    ('Freeman St','Simpson St'),
    ('Simpson St','Intervale Ave'),
    ('Intervale Ave','Prospect Ave - 2-5'),
    ('Prospect Ave - 2-5','Jackson Ave'),
    ('Jackson Ave','3rd Ave - 149th St'),
    ('3rd Ave - 149th St','149th St - Grand Concourse - 2-5'),
    ('149th St - Grand Concourse - 2-5','135th St - 2-3'),
    ('135th St - 2-3','125th St - 2-3'),
    ('125th St - 2-3','116th St - 2-3'),
    ('116th St - 2-3','Central Park North (110th St)'),
    ('Central Park North (110th St)','96th St - 1-2-3'),
    ('96th St - 1-2-3','72nd St - 1-2-3'),
    ('72nd St - 1-2-3','Times Sq - 42nd St - 1-2-3'),
    ('Times Sq - 42nd St - 1-2-3','34th St - Penn Station - 1-2-3'),
    ('34th St - Penn Station - 1-2-3','14th St - 1-2-3'),
    ('14th St - 1-2-3','Chambers St - 1-2-3'),
    ('Chambers St - 1-2-3','Park Pl - 2-3'),
    ('Park Pl - 2-3','Fulton St - 2-3'),
    ('Fulton St - 2-3','Wall St - 2-3'),
    ('Wall St - 2-3','Clark St'),
    ('Clark St','Borough Hall - 2-3'),
    ('Borough Hall - 2-3','Hoyt St'),
    ('Hoyt St','Nevins St'),
    ('Nevins St',"Atlantic Av - Barclay's Center - 2-3-4-5"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5",'Bergen St - 2-3-4'),
    ('Bergen St - 2-3-4','Grand Army Plaza'),
    ('Grand Army Plaza','Eastern Pkwy - Bklyn Museum'),
    ('Eastern Pkwy - Bklyn Museum','Franklin Ave - 2-3-4-5'),
    ('Franklin Ave - 2-3-4-5','President St'),
    ('President St','Sterling St'),
    ('Sterling St','Winthrop St'),
    ('Winthrop St','Church Ave - 2-5'),
    ('Church Ave - 2-5','Beverly Rd - 2-5'),
    ('Beverly Rd - 2-5','Newkirk Ave - 2-5'),
    ('Newkirk Ave - 2-5','Brooklyn College - Flatbush Ave')    
    ]

In [27]:
Edges2LateNight=[
    ('96th St - 1-2-3','86th St - 1-2'),
    ('86th St - 1-2','79th St - 1-2'),
    ('72nd St - 1-2-3','66th St - Lincoln Ctr'),
    ('66th St - Lincoln Ctr','59th St - Columbus Circle - 1-2'),
    ('59th St - Columbus Circle - 1-2','50th St - 1-2'),
    ('50th St - 1-2','Times Sq - 42nd St - 1-2-3'), 
    ('34th St - Penn Station - 1-2-3','28th St - 1-2'),
    ('28th St - 1-2','23rd St - 1-2'), 
    ('23rd St - 1-2','18th St'), 
    ('18th St','14th St - 1-2-3'), 
    ('14th St - 1-2-3','Christopher St - Sheridan Sq'),
    ('Christopher St - Sheridan Sq','Houston St'), 
    ('Houston St','Canal St - 1-2'), 
    ('Canal St - 1-2','Franklin St'), 
    ('Franklin St','Chambers St - 1-2-3')
    ]

In [28]:
Edges3=[
    ('Harlem - 148 St','145th St - 3'),#First 5 cars to get off at 145 st
    ('145th St - 3','135th St - 2-3'),
    ('135th St - 2-3','125th St - 2-3'),
    ('125th St - 2-3','116th St - 2-3'),
    ('116th St - 2-3','Central Park North (110th St)'),
    ('Central Park North (110th St)','96th St - 1-2-3'),
    ('96th St - 1-2-3','72nd St - 1-2-3'),
    ('72nd St - 1-2-3','Times Sq - 42nd St - 1-2-3'),
    ('Times Sq - 42nd St - 1-2-3','34th St - Penn Station - 1-2-3'),
    ('34th St - Penn Station - 1-2-3','14th St - 1-2-3'),
    ('14th St - 1-2-3','Chambers St - 1-2-3'),
    ('Chambers St - 1-2-3','Park Pl - 2-3'),
    ('Park Pl - 2-3','Fulton St - 2-3'),
    ('Fulton St - 2-3','Wall St - 2-3'),
    ('Wall St - 2-3','Clark St'),
    ('Clark St','Borough Hall - 2-3'),
    ('Borough Hall - 2-3','Hoyt St'),
    ('Hoyt St','Nevins St'),
    ('Nevins St',"Atlantic Av - Barclay's Center - 2-3-4-5"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5",'Bergen St - 2-3-4'),
    ('Bergen St - 2-3-4','Grand Army Plaza'),
    ('Grand Army Plaza','Eastern Pkwy - Bklyn Museum'),
    ('Eastern Pkwy - Bklyn Museum','Franklin Ave - 2-3-4-5'),
    ('Franklin Ave - 2-3-4-5','Nostrand Ave - 3-4'),
    ('Nostrand Ave - 3-4','Kingston Ave'),
    ('Kingston Ave','Crown Hts - Utica Ave'),
    ('Crown Hts - Utica Ave','Sutter Ave - Rutland Road'),
    ('Sutter Ave - Rutland Road','Saratoga Ave'),
    ('Saratoga Ave','Rockaway Ave - 3-4'),
    ('Rockaway Ave - 3-4','Junius St'),
    ('Junius St','Pennsylvania Ave'),
    ('Pennsylvania Ave','Van Siclen Ave - 3-4'),
    ('Van Siclen Ave - 3-4','New Lots Ave - 3-4')
    ]

In [29]:
Edges3LateNight=[
    ('Harlem - 148 St','145th St - 3'),#First 5 cars to get off at 145 st
    ('145th St - 3','135th St - 2-3'),
    ('135th St - 2-3','125th St - 2-3'),
    ('125th St - 2-3','116th St - 2-3'),
    ('116th St - 2-3','Central Park North (110th St)'),
    ('Central Park North (110th St)','96th St - 1-2-3'),
    ('96th St - 1-2-3','72nd St - 1-2-3'),
    ('72nd St - 1-2-3','Times Sq - 42nd St - 1-2-3'),
    ]

In [30]:
Edges4 = [
    ('Woodlawn','Mosholu Pkwy'),
    ('Mosholu Pkwy','Bedford Park Blvd - Lehman College'),
    ('Bedford Park Blvd - Lehman College','Kingsbridge Rd - 4'),
    ('Kingsbridge Rd - 4','Fordham Rd - 4'),
    ('Fordham Rd - 4','183rd St'),
    ('183rd St','Burnside Ave'),
    ('Burnside Ave','176th St'),
    ('176th St','Mt Eden Ave'),
    ('Mt Eden Ave','170th St - 4'),
    ('170th St - 4','167th St - 4'),
    ('167th St - 4','161st St - Yankee Stadium - 4'),
    ('161st St - Yankee Stadium - 4','149th St - Grand Concourse - 4'),
    #skipping the 138th station during rush hours
    ('149th St - Grand Concourse - 4','138th St - Grand Concourse'),
    ('138th St - Grand Concourse','125th St - 4-5-6-6'),
    ('125th St - 4-5-6-6','86th St - 4-5-6-6'),
    ('86th St - 4-5-6-6','Lexington Ave - 59th St - 4-5-6-6'),
    ('Lexington Ave - 59th St - 4-5-6-6','Grand Central - 42nd St - 4-5-6-6'),
    ('Grand Central - 42nd St - 4-5-6-6','Union Sq - 14th St - 4-5-6-6'),
    ('Union Sq - 14th St - 4-5-6-6','Brooklyn Bridge - City Hall'),
    ('Brooklyn Bridge - City Hall','Fulton St - 4-5'),
    ('Fulton St - 4-5','Wall St - 4-5'),
    ('Wall St - 4-5','Bowling Green'),
    ('Bowling Green','Borough Hall - 4-5'),
    ('Borough Hall - 4-5','Nevins St'),
    ('Nevins St',"Atlantic Av - Barclay's Center - 2-3-4-5"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5",'Franklin Ave - 2-3-4-5'),
    ('Franklin Ave - 2-3-4-5','Crown Hts - Utica Ave')
    ]

In [31]:
Edges4RushHour=[
    ('Burnside Ave','167th St - 4'),
    ('149th St - Grand Concourse - 4','125th St - 4-5-6-6'),
    ]

In [32]:
Edges4LateNight=[
    ('125th St - 4-5-6-6' , '116th St - 4-6-6'),
    ('116th St - 4-6-6','110th St'),
    ('110th St','103rd St - 4-6-6'),
    ('103rd St - 4-6-6','96th St - 4-6-6'),
    ('96th St - 4-6-6','86th St - 4-5-6-6'),
    ('86th St - 4-5-6-6','77th St - 4-6-6'), 
    ('77th St - 4-6-6','68th St - Hunter College'),
    ('68th St - Hunter College','Lexington Ave - 59th St - 4-5-6-6'),
    ('Lexington Ave - 59th St - 4-5-6-6','51st St'),
    ('51st St','Grand Central - 42nd St - 4-5-6-6'),
    ('Grand Central - 42nd St - 4-5-6-6','33rd St - 4-6-6'),
    ('33rd St - 4-6-6','28th St - 4-6-6'),
    ('28th St - 4-6-6','23rd St - 4-6-6'),
    ('23rd St - 4-6-6','Union Sq - 14th St - 4-5-6-6'),
    ('Union Sq - 14th St - 4-5-6-6','Astor Pl'),
    ('Astor Pl','Bleecker St'),
    ('Bleecker St','Spring St - 4-6-6'),
    ('Spring St - 4-6-6','Canal St - 4-6-6'),
    ('Canal St - 4-6-6','Brooklyn Bridge - City Hall'),
    ("Atlantic Av - Barclay's Center - 2-3-4-5",'Bergen St - 2-3-4'),
    ('Bergen St - 2-3-4','Grand Army Plaza'),
    ('Grand Army Plaza','Eastern Pkwy - Bklyn Museum'),
    ('Eastern Pkwy - Bklyn Museum','Franklin Ave - 2-3-4-5'),
    ('Franklin Ave - 2-3-4-5','Nostrand Ave - 3-4'),
    ('Nostrand Ave - 3-4','Kingston Ave'),
    ('Kingston Ave','Crown Hts - Utica Ave'),
    ('Crown Hts - Utica Ave','Sutter Ave - Rutland Road'),
    ('Sutter Ave - Rutland Road','Saratoga Ave'),
    ('Saratoga Ave','Rockaway Ave - 3-4'),
    ('Rockaway Ave - 3-4','Junius St'),
    ('Junius St','Pennsylvania Ave'),
    ('Pennsylvania Ave','Van Siclen Ave - 3-4'),
    ('Van Siclen Ave - 3-4','New Lots Ave - 3-4')
    ]

In [33]:
#http://web.mta.info/nyct/service/pdf/t5cur.pdf
Edges5 = [
    ('Eastchester - Dyre Ave','Baychester Ave'),
    ('Baychester Ave','Gun Hill Rd - 5'),
    ('Gun Hill Rd - 5','Pelham Pkwy - 5'),
    ('Pelham Pkwy - 5','Morris Park'),
    ('Morris Park','E 180th St'),
    ####Bellow 
#Weekdays daytime, most 5 trains operate between either Dyre Av or 238 StNereid
#Av, Bronx, and Flatbush Av-Brooklyn College, Brooklyn. At all other
#times except during late nights, 5 trains operate between Dyre Av, Bronx, and
#Bowling Green, Manhattan. During late nights 5 trains operate only in the
#Bronx between Dyre Av and E 180 St/Morris Park Av. Customers who ride
#during late night hours can transfer to 2 service at the E 180 St Station.
#At all times, 5 trains operate express in Manhattan and Brooklyn. Weekdays,
#5 trains in the Bronx operate express from E 180 St to 3 Av-149 St during
#morning rush hours (from about 6 AM to 9 AM), and from 3 Av-149 St to
#E 180 St during the evening rush hours (from about 4 PM to 7 PM).
    ('E 180th St','West Farms Sq - E Tremont Av'),
    ('West Farms Sq - E Tremont Av','174th St'),
    ('174th St','Freeman St'),
    ('Freeman St','Simpson St'),
    ('Simpson St','Intervale Ave'),
    ('Intervale Ave','Prospect Ave - 2-5'),
    ('Prospect Ave - 2-5','Jackson Ave'),
    ('Jackson Ave','3rd Ave - 149th St'),
    ('3rd Ave - 149th St','138th St - Grand Concourse'),
    ('138th St - Grand Concourse','125th St - 4-5-6-6'),
    ('125th St - 4-5-6-6','86th St - 4-5-6-6'),
    ('86th St - 4-5-6-6','Lexington Ave - 59th St - 4-5-6-6'),
    ('Lexington Ave - 59th St - 4-5-6-6','Grand Central - 42nd St - 4-5-6-6'),
    ('Grand Central - 42nd St - 4-5-6-6','Union Sq - 14th St - 4-5-6-6'),
    ('Union Sq - 14th St - 4-5-6-6','Brooklyn Bridge - City Hall'),
    ('Brooklyn Bridge - City Hall','Fulton St - 4-5'),
    ('Fulton St - 4-5','Wall St - 4-5'),
    ('Wall St - 4-5','Bowling Green'),
    ('Bowling Green','Borough Hall - 4-5'),
    ('Borough Hall - 4-5','Nevins St'),
    ('Nevins St',"Atlantic Av - Barclay's Center - 2-3-4-5"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5",'Franklin Ave - 2-3-4-5'),
    ('Franklin Ave - 2-3-4-5','President St'),
    ('President St','Sterling St'),
    ('Sterling St','Winthrop St'),
    ('Winthrop St','Church Ave - 2-5'),
    ('Church Ave - 2-5','Beverly Rd - 2-5'),
    ('Beverly Rd - 2-5','Newkirk Ave - 2-5'),
    ('Newkirk Ave - 2-5','Brooklyn College - Flatbush Ave')
    ]

In [34]:
Edges5RushHour = [
    ('Nereid Ave (238 St)','233rd St'),
    ('233rd St','225th St'),
    ('225th St','219th St'),
    ('219th St','Gun Hill Rd - 2-5'),
    ('Gun Hill Rd - 2-5','Burke Ave'),
    ('Burke Ave','Allerton Ave'),
    ('Allerton Ave','Pelham Pkwy - 2-5'),
    ('Pelham Pkwy - 2-5','Bronx Park East'),
    ('Bronx Park East','E 180th St')
    ]

In [35]:
#http://web.mta.info/nyct/service/pdf/t6cur.pdf
#6 local trains operate between Pelham Bay Park/Bruckner Expwy, Bronx, and
#Brooklyn Bridge/City Hall, Manhattan, at all times. Weekday mornings some
#6 trains (denoted below by a color bar) operate express toward Manhattan.
#Weekday afternoons and evenings, these trains operate express to the Bronx.
Edges6 = [
    ('Pelham Bay Park','Buhre Ave'),
    ('Buhre Ave','Middletown Rd'),
    ('Middletown Rd','Westchester Sq - E Tremont Ave'),
    ('Westchester Sq - E Tremont Ave','Zerega Ave'),
    ('Zerega Ave','Castle Hill Ave'),
    ('Castle Hill Ave','Parkchester'),
    ('Parkchester','St Lawrence Ave'),###express
    ('St Lawrence Ave','Morrison Av - Soundview'),
    ('Morrison Av - Soundview','Elder Ave'),
    ('Elder Ave','Whitlock Ave'),
    ('Whitlock Ave','Hunts Point Ave'),
    ('Hunts Point Ave','Longwood Ave'),###express
    ('Longwood Ave','E 149th St'),
    ("E 149th St","E 143rd St - St Mary's St"),
    ("E 143rd St - St Mary's St",'Cypress Ave'),
    ('Cypress Ave','Brook Ave'),
    ('Brook Ave','3rd Ave - 138th St'),
    ('3rd Ave - 138th St','125th St - 4-5-6-6'),
    ('125th St - 4-5-6-6','116th St - 4-6-6'),
    ('116th St - 4-6-6','110th St'),
    ('110th St','103rd St - 4-6-6'),
    ('103rd St - 4-6-6','96th St - 4-6-6'),
    ('96th St - 4-6-6','86th St - 4-5-6-6'),
    ('86th St - 4-5-6-6','77th St - 4-6-6'),
    ('77th St - 4-6-6','68th St - Hunter College'),
    ('68th St - Hunter College','Lexington Ave - 59th St - 4-5-6-6'),
    ('Lexington Ave - 59th St - 4-5-6-6','51st St'),
    ('51st St','Grand Central - 42nd St - 4-5-6-6'),
    ('Grand Central - 42nd St - 4-5-6-6','33rd St - 4-6-6'),
    ('33rd St - 4-6-6','28th St - 4-6-6'),
    ('28th St - 4-6-6','23rd St - 4-6-6'),
    ('23rd St - 4-6-6','Union Sq - 14th St - 4-5-6-6'),
    ('Union Sq - 14th St - 4-5-6-6','Astor Pl'),
    ('Astor Pl','Bleecker St'),
    ('Bleecker St','Spring St - 4-6-6'),
    ('Spring St - 4-6-6','Canal St - 4-6-6'),
    ('Canal St - 4-6-6','Brooklyn Bridge - City Hall')
    ]

In [36]:
Edges7=[
    ('Flushing - Main St','Mets - Willets Point'),
    ('Mets - Willets Point','111th St - 7'),
    ('111th St - 7','103rd St - Corona Plaza'),
    ('103rd St - Corona Plaza','Junction Blvd'),
    ('Junction Blvd','90th St - Elmhurst Av'),
    ('90th St - Elmhurst Av','82nd St - Jackson Hts'),
    ('82nd St - Jackson Hts','74th St - Broadway'),
    ('74th St - Broadway','69th St'),
    ('69th St','Woodside - 61st St'),
    ('Woodside - 61st St','52nd St'),
    ('52nd St','46th St - 7'),
    ('46th St - 7','40th St'),
    ('40th St','33rd St - 7'),
    ('33rd St - 7','Queensboro Plz'),
    ('Queensboro Plz','Court Sq'),
    ('Court Sq','Hunters Point Ave'),
    ('Hunters Point Ave','Vernon Blvd - Jackson Ave'),
    ('Vernon Blvd - Jackson Ave','Grand Central - 42nd St - 7-7'),
    ('Grand Central - 42nd St - 7-7','5th Ave - Bryant Pk'),
    ('5th Ave - Bryant Pk','Times Sq - 42nd St - 7-7'),
    ('Times Sq - 42nd St - 7-7','34th St - Hudson Yards')
    ]

In [37]:
#Train operates in one direction (To Manhattan AM, from Manhattan PM)
Edges7RushHour=[
    ('Queensboro Plz','Woodside - 61st St'),
    ('Woodside - 61st St','Junction Blvd'),
    ('Junction Blvd','Mets - Willets Point'),
]

In [38]:
EdgesA=[
    ('Inwood - 207th St', 'Dyckman St - A'),
    ('Dyckman St - A', '190th St'),
    ('190th St', '181st St - A'),
    ('181st St - A', '175th St'),
    ('175th St','168th St - A-C'),
    ('168th St - A-C','145th St - A-B-C-D'),
    ('145th St - A-B-C-D','125th St - A-B-C-D'),
    ('125th St - A-B-C-D','59th St - Columbus Circle - A-B-C-D'),
    ('59th St - Columbus Circle - A-B-C-D','42nd St - Port Authority Bus Term'), 
    ('42nd St - Port Authority Bus Term','34th St - Penn Station - A-C-E'),
    ('34th St - Penn Station - A-C-E','14th St - A-C-E'),
    ('14th St - A-C-E','W 4th St - Washington Sq (Upper)'),
    ('W 4th St - Washington Sq (Upper)','Canal St - Holland Tunnel'),
    ('Canal St - Holland Tunnel','Chambers St - A-C'),
    ('Chambers St - A-C','Fulton St - A-C'),
    ('Fulton St - A-C','High St'),
    ('High St','Jay St - MetroTech - A-C-F'),
    ('Jay St - MetroTech - A-C-F','Hoyt - Schermerhorn Sts'),
    ('Hoyt - Schermerhorn Sts','Nostrand Ave - A-C'),
    ('Nostrand Ave - A-C','Utica Ave'),
    ('Utica Ave','Broadway Junction - A-C'),
    ('Broadway Junction - A-C','Euclid Ave'),
    ('Euclid Ave','Grant Ave'),
    ('Grant Ave','80th St'),
    ('80th St','88th St'),
    ('88th St','Rockaway Blvd'),
    ('Rockaway Blvd','104th St'),
    ('104th St','111th St - A-S'),
    ('111th St - A-S','Ozone Park - Lefferts Blvd'),
    ('Rockaway Blvd','Aqueduct - North Conduit Av'),##one direction
    ('Aqueduct Racetrack','Rockaway Blvd'), ##one direction
    ('Aqueduct - North Conduit Av','Howard Beach - JFK Airport'),##one direction
    ('Howard Beach - JFK Airport','Aqueduct Racetrack'),##one direction
    ('Howard Beach - JFK Airport','Broad Channel'),
    ('Broad Channel','Beach 67th St'),
    ('Beach 67th St','Beach 60th St'),
    ('Beach 60th St','Beach 44th St'),
    ('Beach 44th St','Beach 36th St'),
    ('Beach 36th St','Beach 25th St'),
    ('Beach 25th St','Far Rockaway - Mott Ave'),
    ('Broad Channel','Beach 90th St'),
    ('Beach 90th St','Beach 98th St'),
    ('Beach 98th St','Beach 105th St'),
    ('Beach 105th St','Rockaway Park - Beach 116 St')]

In [39]:
getclosest('B')


(37L,)
(37L, 37L)
Cathedral Pkwy (110th St) - A-B-C , 116th St - A-B-C
DeKalb Ave - B-D-N-Q-R , Atlantic Av - Barclay's Center - B-Q
182nd-183rd Sts , Fordham Rd - B-D
174th-175th Sts , Tremont Ave
167th St - B-D , 170th St - B-D
72nd St - A-B-C , 81st St
96th St - A-B-C , 103rd St - A-B-C
Kingsbridge Rd - B-D , Fordham Rd - B-D
42nd St - Bryant Pk , Herald Sq - 34th St - B-D-F-M
Prospect Park , Church Ave - B-Q
W 4th St - Washington Sq (Lower) , Broadway - Lafayette St
Church Ave - B-Q , Prospect Park
Newkirk Ave - B-Q , Church Ave - B-Q
7th Ave - B-Q , Atlantic Av - Barclay's Center - B-Q
Atlantic Av - Barclay's Center - B-Q , DeKalb Ave - B-D-N-Q-R
103rd St - A-B-C , 96th St - A-B-C
81st St , 86th St - A-B-C
86th St - A-B-C , 81st St
Tremont Ave , 174th-175th Sts
170th St - B-D , 174th-175th Sts
Fordham Rd - B-D , 182nd-183rd Sts
Bedford Park Blvd , Kingsbridge Rd - B-D
145th St - A-B-C-D , 135th St - A-B-C
155th St - B-D , 145th St - A-B-C-D
161st St - Yankee Stadium - B-D , 167th St - B-D
Brighton Beach , Sheepshead Bay
Sheepshead Bay , Brighton Beach
Kings Hwy - B-Q , Sheepshead Bay
7th Ave - B-D-E , 47th-50th Sts - Rockefeller Ctr
47th-50th Sts - Rockefeller Ctr , 7th Ave - B-D-E
59th St - Columbus Circle - A-B-C-D , 7th Ave - B-D-E
Herald Sq - 34th St - B-D-F-M , 42nd St - Bryant Pk
116th St - A-B-C , Cathedral Pkwy (110th St) - A-B-C
125th St - A-B-C-D , 116th St - A-B-C
Grand St - B-D , Broadway - Lafayette St
Broadway - Lafayette St , Grand St - B-D
135th St - A-B-C , 145th St - A-B-C-D

In [40]:
EdgesB=[
    ('Bedford Park Blvd','Kingsbridge Rd - B-D'),
    ('Kingsbridge Rd - B-D','Fordham Rd - B-D'),
    ('Fordham Rd - B-D','182nd-183rd Sts'),
    ('182nd-183rd Sts','Tremont Ave'), 
    ('Tremont Ave','174th-175th Sts'),
    ('174th-175th Sts','170th St - B-D'),
    ('170th St - B-D','167th St - B-D'),
    ('167th St - B-D','161st St - Yankee Stadium - B-D'),
    ('161st St - Yankee Stadium - B-D','155th St - B-D'),
    ('155th St - B-D','145th St - A-B-C-D'),
    ('145th St - A-B-C-D','135th St - A-B-C'),
    ('135th St - A-B-C','125th St - A-B-C-D'),
    ('125th St - A-B-C-D','116th St - A-B-C'),
    ('116th St - A-B-C','Cathedral Pkwy (110th St) - A-B-C'),
    ('Cathedral Pkwy (110th St) - A-B-C','103rd St - A-B-C'), 
    ('103rd St - A-B-C','96th St - A-B-C'),
    ('96th St - A-B-C','86th St - A-B-C'),
    ('86th St - A-B-C','81st St'),
    ('81st St','72nd St - A-B-C'),
    ('72nd St - A-B-C','59th St - Columbus Circle - A-B-C-D'),
    ('59th St - Columbus Circle - A-B-C-D','7th Ave - B-D-E'),
    ('7th Ave - B-D-E','47th-50th Sts - Rockefeller Ctr'),
    ('47th-50th Sts - Rockefeller Ctr','42nd St - Bryant Pk'),
    ('42nd St - Bryant Pk','Herald Sq - 34th St - B-D-F-M'),
    ('Herald Sq - 34th St - B-D-F-M','W 4th St - Washington Sq (Lower)'),
    ('W 4th St - Washington Sq (Lower)','Broadway - Lafayette St'),
    ('Broadway - Lafayette St','Grand St - B-D'),
    ('Grand St - B-D',"DeKalb Ave - B-D-N-Q-R"),
    ('DeKalb Ave - B-D-N-Q-R',"Atlantic Av - Barclay's Center - B-Q"),
    ("Atlantic Av - Barclay's Center - B-Q",'7th Ave - B-Q'),
    ('7th Ave - B-Q','Prospect Park'),
    ('Prospect Park','Church Ave - B-Q'),
    ('Church Ave - B-Q','Newkirk Ave - B-Q'),
    ('Newkirk Ave - B-Q','Kings Hwy - B-Q'),
    ('Kings Hwy - B-Q','Sheepshead Bay'),  
    ('Sheepshead Bay','Brighton Beach') 
    ]

In [41]:
EdgesC=[
    ('168th St - A-C','163rd St - Amsterdam Av'),
    ('163rd St - Amsterdam Av','155th St - A-C'),
    ('155th St - A-C','145th St - A-B-C-D'),
    ('145th St - A-B-C-D','135th St - A-B-C'),
    ('135th St - A-B-C','125th St - A-B-C-D'),
    ('125th St - A-B-C-D','116th St - A-B-C'),
    ('116th St - A-B-C','Cathedral Pkwy (110th St) - A-B-C'),
    ('Cathedral Pkwy (110th St) - A-B-C','103rd St - A-B-C'),
    ('103rd St - A-B-C','96th St - A-B-C'),
    ('96th St - A-B-C','86th St - A-B-C'),
    ('86th St - A-B-C','81st St'),
    ('81st St','72nd St - A-B-C'),
    ('72nd St - A-B-C','59th St - Columbus Circle - A-B-C-D'),
    ('59th St - Columbus Circle - A-B-C-D','50th St - A-C-E'),
    ('50th St - A-C-E','42nd St - Port Authority Bus Term'),
    ('42nd St - Port Authority Bus Term','34th St - Penn Station - A-C-E'),
    ('34th St - Penn Station - A-C-E','23rd St - A-C-E'),
    ('23rd St - A-C-E','14th St - A-C-E'),
    ('14th St - A-C-E','W 4th St - Washington Sq (Upper)'),
    ('W 4th St - Washington Sq (Upper)','Spring St - A-C-E'),
    ('Spring St - A-C-E','Canal St - Holland Tunnel'),
    ('Canal St - Holland Tunnel','Chambers St - A-C'),
    ('Chambers St - A-C','Fulton St - A-C'),
    ('Fulton St - A-C','High St'),
    ('High St','Jay St - MetroTech - A-C-F'),
    ('Jay St - MetroTech - A-C-F','Hoyt - Schermerhorn Sts'),
    ('Hoyt - Schermerhorn Sts','Lafayette Ave'),
    ('Lafayette Ave','Clinton - Washington Aves - A-C'),
    ('Clinton - Washington Aves - A-C','Franklin Ave - A-C'),
    ('Franklin Ave - A-C','Nostrand Ave - A-C'),
    ('Nostrand Ave - A-C','Kingston - Throop Aves'),
    ('Kingston - Throop Aves','Utica Ave'),
    ('Utica Ave','Ralph Ave'),
    ('Ralph Ave','Rockaway Ave - A-C'),
    ('Rockaway Ave - A-C','Broadway Junction - A-C'),
    ('Broadway Junction - A-C','Liberty Ave'),
    ('Liberty Ave','Van Siclen Ave - A-C'),
    ('Van Siclen Ave - A-C','Shepherd Ave'),
    ('Shepherd Ave','Euclid Ave')
    ]

In [42]:
EdgesD=[
    ('Norwood - 205th St','Bedford Park Blvd'),
    ('Bedford Park Blvd','Kingsbridge Rd - B-D'),
    ('Kingsbridge Rd - B-D','Fordham Rd - B-D'),
    ('Fordham Rd - B-D','182nd-183rd Sts'),
    ('182nd-183rd Sts','Tremont Ave'), 
    ('Tremont Ave','174th-175th Sts'),
    ('174th-175th Sts','170th St - B-D'),
    ('170th St - B-D','167th St - B-D'),
    ('167th St - B-D','161st St - Yankee Stadium - B-D'),
    ('161st St - Yankee Stadium - B-D','155th St - B-D'),
    ('155th St - B-D','145th St - A-B-C-D'),
    ('145th St - A-B-C-D','125th St - A-B-C-D'), 
    ('125th St - A-B-C-D','59th St - Columbus Circle - A-B-C-D'),
    ('59th St - Columbus Circle - A-B-C-D','7th Ave - B-D-E'),
    ('7th Ave - B-D-E','47th-50th Sts - Rockefeller Ctr'),
    ('47th-50th Sts - Rockefeller Ctr','42nd St - Bryant Pk'),
    ('42nd St - Bryant Pk','Herald Sq - 34th St - B-D-F-M'),
    ('Herald Sq - 34th St - B-D-F-M','W 4th St - Washington Sq (Lower)'),
    ('W 4th St - Washington Sq (Lower)','Broadway - Lafayette St'),
    ('Broadway - Lafayette St','Grand St - B-D'),
    ('Grand St - B-D',"Atlantic Av - Barclay's Center - D-N-Q-R"),
    ("Atlantic Av - Barclay's Center - D-N-Q-R",'36th St - D-N-R'),
    ('36th St - D-N-R','9th Ave'),
    ('9th Ave','Ft Hamilton Pkwy - D'),
    ('Ft Hamilton Pkwy - D','50th St - D'),
    ('50th St - D','55th St'),
    ('55th St','62nd St'),
    ('62nd St','71st St'),
    ('71st St','79th St - D'),
    ('79th St - D','18th Ave - D'), 
    ('18th Ave - D','20th Ave - D'),
    ('20th Ave - D','Bay Pky - D'),
    ('Bay Pky - D','25th Ave'),
    ('25th Ave','Bay 50th St'),
    ('Bay 50th St','Coney Island - Stillwell Av'),
    ]

In [43]:
EdgesE = [
    ('Jamaica Ctr - Parsons / Archer','Sutphin Blvd - Archer Av'),
    ('Sutphin Blvd - Archer Av','Jamaica - Van Wyck'),
    ('Jamaica - Van Wyck','Briarwood - Van Wyck Blvd'),
    ('Briarwood - Van Wyck Blvd','Kew Gardens - Union Tpke'),
    ('Kew Gardens - Union Tpke','75th Ave'),
    ('75th Ave','Forest Hills - 71st Av'),
    ('Forest Hills - 71st Av','Jackson Hts - Roosevelt Av'),
    ('Jackson Hts - Roosevelt Av','Queens Plz'),
    ('Queens Plz','Court Sq - 23rd St'),
    ('Court Sq - 23rd St','Lexington Ave - 53rd St'),
    ('Lexington Ave - 53rd St','5th Ave - 53rd St'),
    ('5th Ave - 53rd St','7th Ave - B-D-E'),
    ('7th Ave - B-D-E','50th St - A-C-E'),
    ('50th St - A-C-E','42nd St - Port Authority Bus Term'),
    ('42nd St - Port Authority Bus Term','34th St - Penn Station - A-C-E'),
    ('34th St - Penn Station - A-C-E','23rd St - A-C-E'),
    ('23rd St - A-C-E','14th St - A-C-E'),
    ('14th St - A-C-E','W 4th St - Washington Sq (Upper)'),
    ('W 4th St - Washington Sq (Upper)','Spring St - A-C-E'),
    ('Spring St - A-C-E','Canal St - Holland Tunnel'),
    ('Canal St - Holland Tunnel','World Trade Center')
    ]

In [44]:
EdgesF=[
    ("Jamaica - 179th St","169th St"),
    ("169th St","Parsons Blvd"),
    ("Parsons Blvd","Sutphin Blvd"),
    ("Sutphin Blvd","Briarwood - Van Wyck Blvd"),
    ("Briarwood - Van Wyck Blvd","Kew Gardens - Union Tpke"),
    ("Kew Gardens - Union Tpke","75th Ave"),
    ("75th Ave","Forest Hills - 71st Av"),
    ("Forest Hills - 71st Av","Jackson Hts - Roosevelt Av"),
    ("Jackson Hts - Roosevelt Av","21st St - Queensbridge"),
    ("21st St - Queensbridge","Roosevelt Island - Main St"),
    ("Roosevelt Island - Main St","Lexington Ave - 63rd St"),
    ("Lexington Ave - 63rd St","57th St - F"),
    ("57th St - F","47th-50th Sts - Rockefeller Ctr"),
    ("47th-50th Sts - Rockefeller Ctr","42nd St - Bryant Pk"),
    ("42nd St - Bryant Pk","Herald Sq - 34th St - B-D-F-M"),
    ("Herald Sq - 34th St - B-D-F-M","23rd St - F-M"),
    ("23rd St - F-M","14th St - F-M"),
    ("14th St - F-M","W 4th St - Washington Sq (Lower)"),
    ("W 4th St - Washington Sq (Lower)","Broadway - Lafayette St"),
    ("Broadway - Lafayette St","Lower East Side - 2nd Ave"),
    ("Lower East Side - 2nd Ave","Delancey St - Essex St - F"),
    ("Delancey St - Essex St - F","East Broadway"),
    ("East Broadway","York St"),
    ("York St","Jay St - MetroTech - A-C-F"),
    ("Jay St - MetroTech - A-C-F","Bergen St - F-G"),
    ("Bergen St - F-G","Carroll St"),
    ("Carroll St","Smith - 9th Sts"),
    ("Smith - 9th Sts","4th Av - 9th St - F-G"),
    ("4th Av - 9th St - F-G","7th Ave - F-G"),
    ("7th Ave - F-G","15th St - Prospect Park"),
    ("15th St - Prospect Park","Ft Hamilton Pkwy - F-G"),
    ("Ft Hamilton Pkwy - F-G","Church Ave - F-G"),
    ("Church Ave - F-G","Ditmas Ave"),
    ("Ditmas Ave","18th Ave - F"),
    ("18th Ave - F","Ave I"),
    ("Ave I","Bay Pky - F"),
    ("Bay Pky - F","Ave N"),
    ("Ave N","Ave P"),
    ("Ave P","Kings Hwy - F"),
    ("Kings Hwy - F","Ave U - F"), 
    ("Ave U - F","Ave X"),
    ("Ave X","Neptune Ave"),
    ("Neptune Ave","W 8th St - NY Aquarium"),
    ('W 8th St - NY Aquarium','Coney Island - Stillwell Av')
    ]

In [45]:
EdgesG=[
    ('Long Island City - Court Sq','21st St'),
    ('21st St','Greenpoint Ave'),
    ('Greenpoint Ave','Nassau Ave'),
    ('Nassau Ave','Metropolitan Ave'),
    ('Metropolitan Ave','Broadway - G'),
    ('Broadway - G','Flushing Ave - G'),
    ('Flushing Ave - G','Myrtle-Willoughby Aves'),
    ('Myrtle-Willoughby Aves','Bedford - Nostrand Aves'),
    ('Bedford - Nostrand Aves','Classon Ave'),
    ('Classon Ave','Clinton - Washington Aves - G'),
    ('Clinton - Washington Aves - G','Fulton St - G'),
    ('Fulton St - G','Hoyt - Schermerhorn Sts'),
    ('Hoyt - Schermerhorn Sts','Bergen St - F-G'),
    ('Bergen St - F-G','Carroll St'),
    ('Carroll St','Smith - 9th Sts'),
    ('Smith - 9th Sts','4th Av - 9th St - F-G'),
    ('4th Av - 9th St - F-G','7th Ave - F-G'),
    ('7th Ave - F-G','15th St - Prospect Park'),
    ('15th St - Prospect Park','Ft Hamilton Pkwy - F-G'),
    ('Ft Hamilton Pkwy - F-G','Church Ave - F-G')
    ]

In [46]:
EdgesJ=[
    ('Broad St','Fulton St - J-Z'),
    ('Fulton St - J-Z','Chambers St - J-Z'),
    ('Chambers St - J-Z','Canal St - J-Z'),
    ('Canal St - J-Z','Bowery'),
    ('Bowery','Delancey St - Essex St - J-M-Z'),
    ('Delancey St - Essex St - J-M-Z','Marcy Ave'), 
    ('Marcy Ave','Hewes St'),
    ('Hewes St','Lorimer St - J-M'),#part time 
    ('Lorimer St - J-M','Flushing Ave - J-M'),#part time
    ('Flushing Ave - J-M','Myrtle Ave'),#part time
    ('Myrtle Ave','Kosciuszko St'),
    ('Kosciuszko St','Gates Ave'),
    ('Gates Ave','Halsey St - J'),#part time
    ('Halsey St - J','Chauncey St'),#part time
    ('Chauncey St','Broadway Junction - J-Z'),
    ('Broadway Junction - J-Z','Alabama Ave'),
    ('Alabama Ave','Van Siclen Ave - J-Z'),#part time
    ('Van Siclen Ave - J-Z','Cleveland St'),#part time
    ('Cleveland St','Norwood Ave'),#part time
    ('Norwood Ave','Crescent St'),#part time
    ('Crescent St','Cypress Hills'),
    ('Cypress Hills','75th St - Eldert Ln'),
    ('75th St - Eldert Ln','85th St - Forest Pky'),
    ('85th St - Forest Pky','Woodhaven Blvd'),
    ('Woodhaven Blvd','104th-102nd Sts'),
    ('104th-102nd Sts','111th St - J'),
    ('111th St - J','121st St'),
    ('121st St','Sutphin Blvd - Archer Av'),
    ('Sutphin Blvd - Archer Av','Jamaica Ctr - Parsons / Archer')
    ]

In [47]:
EdgesL=[
    #('8th Ave - L','6th Ave'),
    #('6th Ave','Union Sq - 14th St - L'),
    #('Union Sq - 14th St - L','3rd Ave'),
    #('3rd Ave','1st Ave'),
    #('1st Ave','Bedford Ave'),
    ('Bedford Ave','Lorimer St - L'),
    ('Lorimer St - L','Graham Ave'),
    ('Graham Ave','Grand St - L'),
    ('Grand St - L','Montrose Ave'),
    ('Montrose Ave','Morgan Ave'),
    ('Morgan Ave','Jefferson St'),
    ('Jefferson St','DeKalb Ave - L'),
    ('DeKalb Ave - L','Myrtle - Wyckoff Aves - L'),
    ('Myrtle - Wyckoff Aves - L','Halsey St - L'),
    ('Halsey St - L','Wilson Ave'),
    ('Wilson Ave','Bushwick - Aberdeen'),
    ('Bushwick - Aberdeen','Broadway Junction - L'),
    ('Broadway Junction - L','Atlantic Ave'),
    ('Atlantic Ave','Sutter Ave'),
    ('Sutter Ave','Livonia Ave'),
    ('Livonia Ave','New Lots Ave - L'),
    ('New Lots Ave - L','E 105th St'),
    ('E 105th St','Canarsie - Rockaway Pkwy')
    ]

In [48]:
EdgesM=[
    ('Middle Village - Metropolitan Ave','Fresh Pond Rd'),
    ('Fresh Pond Rd','Forest Ave'),
    ('Forest Ave','Seneca Ave'),
    ('Seneca Ave','Myrtle - Wyckoff Aves - M'),
    ('Myrtle - Wyckoff Aves - M','Knickerbocker Ave'),
    ('Knickerbocker Ave','Central Ave'),
    ('Central Ave','Myrtle Ave'),  
    ('Myrtle Ave','Flushing Ave - J-M'),
    ('Flushing Ave - J-M','Lorimer St - J-M'),  
    ('Lorimer St - J-M','Hewes St'),
    ('Hewes St','Marcy Ave'),
    ('Marcy Ave','Delancey St - Essex St - J-M-Z'),
    ("Delancey St - Essex St - J-M-Z","Broadway - Lafayette St"),
    ("Broadway - Lafayette St","W 4th St - Washington Sq (Lower)"),
    ("W 4th St - Washington Sq (Lower)","14th St - F-M"),
    ("14th St - F-M","23rd St - F-M"),
    ("23rd St - F-M","Herald Sq - 34th St - B-D-F-M"),
    ("Herald Sq - 34th St - B-D-F-M","42nd St - Bryant Pk"),
    ("42nd St - Bryant Pk","47th-50th Sts - Rockefeller Ctr"),
    ("47th-50th Sts - Rockefeller Ctr","5th Ave - 53rd St"),
    ("5th Ave - 53rd St","Lexington Ave - 53rd St"),
    ("Lexington Ave - 53rd St","Court Sq - 23rd St"),
    ("Court Sq - 23rd St","Queens Plz"),
    ("Queens Plz","36th St - E-M-R"),
    ("36th St - E-M-R","Steinway St"),
    ("Steinway St","46th St - E-M-R"),
    ("46th St - E-M-R","Northern Blvd"),
    ("Northern Blvd","65th St"),
    ("65th St","Jackson Hts - Roosevelt Av"),
    ("Jackson Hts - Roosevelt Av","Elmhurst Ave"),
    ("Elmhurst Ave","Grand Ave - Newtown"),
    ("Grand Ave - Newtown","Woodhaven Blvd - Queens Mall"),
    ("Woodhaven Blvd - Queens Mall","63rd Dr - Rego Park"),
    ("63rd Dr - Rego Park","67th Ave"),
    ("67th Ave","Forest Hills - 71st Av")    
    ]

In [49]:
EdgesN=[
    ("Coney Island - Stillwell Av","Gravesend - 86th St"),
    ("Gravesend - 86th St","Ave U - N"),
    ("Ave U - N","Kings Hwy - N"),
    ("Kings Hwy - N","Bay Pky - N"),
    ("Bay Pky - N","20th Ave - N"),
    ("20th Ave - N","18th Ave - N"),
    ("18th Ave - N","New Utrecht Ave"),
    ("New Utrecht Ave","Ft Hamilton Pkwy - N"),
    ("Ft Hamilton Pkwy - N","8th Ave - N"),
    ("8th Ave - N","59th St"),
    ("59th St","36th St - D-N-R"),
    ("36th St - D-N-R","Atlantic Av - Barclay's Center - D-N-Q-R"),
    ("Atlantic Av - Barclay's Center - D-N-Q-R","Canal St - N-Q"),
    ("Canal St - N-Q","Union Sq - 14th St - N-Q-R-W"),
    ("Union Sq - 14th St - N-Q-R-W","Herald Sq - 34th St - N-Q-R-W"),
    ("Herald Sq - 34th St - N-Q-R-W","Times Sq - 42nd St - N-Q-R-W"),
    ("Times Sq - 42nd St - N-Q-R-W","49th St"),
    ("49th St","57th St - N-Q-R-W"),
    ("57th St - N-Q-R-W","5th Ave - 59th St"),
    ("5th Ave - 59th St","Lexington Ave - 59th St - N-R-W"), 
    ("Lexington Ave - 59th St - N-R-W","Queensboro Plz"),
    ("Queensboro Plz","39th Ave"),
    ("39th Ave","36th Ave"), 
    ("36th Ave","Broadway - N-W"),
    ("Broadway - N-W","30th Ave"), 
    ("30th Ave","Astoria Blvd"),
    ("Astoria Blvd","Astoria - Ditmars Blvd")
    ]

In [50]:
EdgesQ=[
    ('96th St - Q','86th St - Q'),
    ('86th St - Q','72nd St - Q'),
    ('72nd St - Q','Lexington Ave - 63rd St'),
    ('Lexington Ave - 63rd St','57th St - N-Q-R-W'),
    ('57th St - N-Q-R-W','Times Sq - 42nd St - N-Q-R-W'),
    ('Times Sq - 42nd St - N-Q-R-W','Herald Sq - 34th St - N-Q-R-W'),
    ('Herald Sq - 34th St - N-Q-R-W','Union Sq - 14th St - N-Q-R-W'),
    ('Union Sq - 14th St - N-Q-R-W','Canal St - N-Q'), 
    ('Canal St - N-Q','DeKalb Ave - B-D-N-Q-R'),
    ('DeKalb Ave - B-D-N-Q-R',"Atlantic Av - Barclay's Center - B-Q"),
    ("Atlantic Av - Barclay's Center - B-Q",'7th Ave - B-Q'),
    ('7th Ave - B-Q','Prospect Park'),
    ('Prospect Park','Parkside Ave'),
    ('Parkside Ave','Church Ave - B-Q'),
    ('Church Ave - B-Q','Beverly Rd - Q'),
    ('Beverly Rd - Q','Cortelyou Rd'),
    ('Cortelyou Rd','Newkirk Ave - B-Q'),
    ('Newkirk Ave - B-Q','Ave H'),
    ('Ave H','Ave J'),
    ('Ave J','Ave M'),  
    ('Ave M','Kings Hwy - B-Q'),
    ('Kings Hwy - B-Q','Ave U - Q'),
    ('Ave U - Q','Neck Rd'),
    ('Neck Rd','Sheepshead Bay'),
    ('Sheepshead Bay','Brighton Beach'), 
    ('Brighton Beach','Ocean Pkwy'),
    ('Ocean Pkwy','W 8th St - NY Aquarium'),
    ('W 8th St - NY Aquarium','Coney Island - Stillwell Av')
    ]

In [51]:
EdgesR=[
    ('Bay Ridge - 95th St','86th St - R'), 
    ('86th St - R','77th St - R'),
    ('77th St - R','Bay Ridge Ave'),
    ('Bay Ridge Ave','59th St'),
    ('59th St','53rd St'),
    ('53rd St','45th St'),
    ('45th St','36th St - D-N-R'),
    ('36th St - D-N-R','25th St'),
    ('25th St','Prospect Ave - D-N-R'),
    ('Prospect Ave - D-N-R','4th Av - 9th St - D-N-R'),
    ('4th Av - 9th St - D-N-R','Union St'),
    ('Union St',"Atlantic Av - Barclay's Center - D-N-Q-R"),
    ("Atlantic Av - Barclay's Center - D-N-Q-R",'DeKalb Ave - B-D-N-Q-R'),
    ('DeKalb Ave - B-D-N-Q-R','Jay St - MetroTech - N-R'),
    ('Jay St - MetroTech - N-R','Court St'),
    ('Court St','Whitehall St'),
    ('Whitehall St','Rector St - R-W'),
    ('Rector St - R-W','Cortlandt St - R-W'),
    ('Cortlandt St - R-W','City Hall'),
    ('City Hall','Canal St - R-W'),
    ('Canal St - R-W','Prince St'),
    ('Prince St','8th St - NYU'),
    ('8th St - NYU','Union Sq - 14th St - N-Q-R-W'),
    ('Union Sq - 14th St - N-Q-R-W','23rd St - N-Q-R-W'),
    ('23rd St - N-Q-R-W','28th St - N-Q-R-W'),
    ('28th St - N-Q-R-W','Herald Sq - 34th St - N-Q-R-W'),
    ('Herald Sq - 34th St - N-Q-R-W','Times Sq - 42nd St - N-Q-R-W'),
    ('Times Sq - 42nd St - N-Q-R-W','49th St'),
    ('49th St','57th St - N-Q-R-W'),
    ('57th St - N-Q-R-W','5th Ave - 59th St'),
    ('5th Ave - 59th St','Lexington Ave - 59th St - N-R-W'),
    ('Lexington Ave - 59th St - N-R-W','Queens Plz'),
    ('Queens Plz','36th St - E-M-R'),
    ('36th St - E-M-R','Steinway St'),
    ('Steinway St','46th St - E-M-R'),
    ('46th St - E-M-R','Northern Blvd'), 
    ('Northern Blvd','65th St'),
    ('65th St','Jackson Hts - Roosevelt Av'),
    ('Jackson Hts - Roosevelt Av','Elmhurst Ave'),
    ('Elmhurst Ave','Grand Ave - Newtown'),
    ('Grand Ave - Newtown','Woodhaven Blvd - Queens Mall'),
    ('Woodhaven Blvd - Queens Mall','63rd Dr - Rego Park'),
    ('63rd Dr - Rego Park','67th Ave'),
    ('67th Ave','Forest Hills - 71st Av')
    ]

In [52]:
EdgesS=[
    ("Franklin Ave - Fulton St","Park Pl - S"),
    ("Park Pl - S","Botanic Garden"), 
    ("Botanic Garden","Prospect Park"),
    ("Times Sq - 42nd St - S","Grand Central - 42nd St - S"),
    ("Broad Channel","Beach 90th St"),
    ("Beach 90th St","Beach 98th St"),
    ("Beach 98th St","Beach 105th St"),
    ("Beach 105th St","Rockaway Park - Beach 116 St")
    ]

In [53]:
EdgesW=[
    ("Whitehall St","Rector St - R-W"),
    ("Rector St - R-W","Cortlandt St - R-W"),
    ("Cortlandt St - R-W","City Hall"),
    ("City Hall","Canal St - R-W"),
    ("Canal St - R-W","Prince St"),
    ("Prince St","8th St - NYU"),
    ("8th St - NYU","Union Sq - 14th St - N-Q-R-W"),
    ("Union Sq - 14th St - N-Q-R-W","23rd St - N-Q-R-W"),
    ("23rd St - N-Q-R-W","28th St - N-Q-R-W"),
    ("28th St - N-Q-R-W","Herald Sq - 34th St - N-Q-R-W"),
    ("Herald Sq - 34th St - N-Q-R-W","Times Sq - 42nd St - N-Q-R-W"),
    ("Times Sq - 42nd St - N-Q-R-W","49th St"),
    ("49th St","57th St - N-Q-R-W"),
    ("57th St - N-Q-R-W","5th Ave - 59th St"),
    ("5th Ave - 59th St","Lexington Ave - 59th St - N-R-W"), 
    ("Lexington Ave - 59th St - N-R-W","Queensboro Plz"),
    ("Queensboro Plz","39th Ave"),
    ("39th Ave","36th Ave"), 
    ("36th Ave","Broadway - N-W"),
    ("Broadway - N-W","30th Ave"), 
    ("30th Ave","Astoria Blvd"),
    ("Astoria Blvd","Astoria - Ditmars Blvd")
    ]

In [54]:
EdgesZ=[
    ('Broad St','Fulton St - J-Z'),
    ('Fulton St - J-Z','Chambers St - J-Z'),
    ('Chambers St - J-Z','Canal St - J-Z'),
    ('Canal St - J-Z','Bowery'),
    ('Bowery','Delancey St - Essex St - J-M-Z'),
    ('Delancey St - Essex St - J-M-Z','Marcy Ave'), 
    ("Marcy Ave","Myrtle Ave"),
    ("Myrtle Ave","Gates Ave"),
    ("Gates Ave","Chauncey St"),
    ("Chauncey St","Broadway Junction - J-Z"),
    ('Broadway Junction - J-Z','Alabama Ave'),
    ('Alabama Ave','Van Siclen Ave - J-Z'),#part time
    ('Van Siclen Ave - J-Z','Norwood Ave'),
    ('Norwood Ave','Crescent St'),#part time
    ("Crescent St","75th St - Eldert Ln"),
    ("75th St - Eldert Ln","Woodhaven Blvd"),
    ('Woodhaven Blvd','104th-102nd Sts'),
    ('104th-102nd Sts','121st St'),
    ("121st St","Sutphin Blvd - Archer Av"),
    ("Sutphin Blvd - Archer Av","Jamaica Ctr - Parsons / Archer")
    ]

In [55]:
EdgesTransfers=[
    ("4th Av - 9th St - D-N-R","4th Av - 9th St - F-G"),
    ("New Utrecht Ave","62nd St"),
    ("Myrtle - Wyckoff Aves - L","Myrtle - Wyckoff Aves - M"),
    #("Lexington Ave - 63rd St","59th St"),
    ("Jackson Hts - Roosevelt Av","74th St - Broadway"),
    ("Court Sq - 23rd St","Court Sq"),
    ("Lorimer St - L","Metropolitan Ave"),
    #("Union Sq - 14th St - 4-5-6-6","Union Sq - 14th St - L"),
    #("Union Sq - 14th St - N-Q-R-W","Union Sq - 14th St - L"),
    ("Union Sq - 14th St - N-Q-R-W","Union Sq - 14th St - 4-5-6-6"),
    ("Bleecker St","Broadway - Lafayette St"),
    ("Canal St - N-Q","Canal St - 4-6-6"),
    ("Canal St - 4-6-6","Canal St - J-Z"),
    ("Brooklyn Bridge - City Hall","Chambers St - J-Z"),
    ("42nd St - Bryant Pk","5th Ave - Bryant Pk"),
    ("Herald Sq - 34th St - B-D-F-M","Herald Sq - 34th St - N-Q-R-W"),
    ("Delancey St - Essex St - F","Delancey St - Essex St - J-M-Z"),
    ("South Ferry","Whitehall St"),
    #("14th St - A-C-E","8th Ave - L"),
    ("W 4th St - Washington Sq (Lower)","W 4th St - Washington Sq (Upper)"),
    ("Jay St - MetroTech - A-C-F","Jay St - MetroTech - N-R"),
    ("Franklin Ave - A-C","Franklin Ave - Fulton St"),
    ("Broadway Junction - A-C","Broadway Junction - J-Z"),
    ("Broadway Junction - A-C","Broadway Junction - L"),
    ("Broadway Junction - J-Z","Broadway Junction - L"),
    ("161st St - Yankee Stadium - 4","161st St - Yankee Stadium - B-D"),
    #("59th St","Lexington Ave - 59th St - N-R-W"),
    ("51st St","Lexington Ave - 53rd St"),
    ("Grand Central - 42nd St - 4-5-6-6","Grand Central - 42nd St - 7-7"),
    ("Grand Central - 42nd St - 4-5-6-6","Grand Central - 42nd St - S"),
    ("Grand Central - 42nd St - 7-7","Grand Central - 42nd St - S"),
    ("168th St - A-C","168th St - 1"),
    ("149th St - Grand Concourse - 2-5","149th St - Grand Concourse - 4"),#notsure
    ("59th St - Columbus Circle - A-B-C-D","59th St - Columbus Circle - 1-2"),
    ("Times Sq - 42nd St - 1-2-3","Times Sq - 42nd St - 7-7"),
    ("Times Sq - 42nd St - 1-2-3","Times Sq - 42nd St - N-Q-R-W"),
    ("Times Sq - 42nd St - 1-2-3","Times Sq - 42nd St - S"),
    ("Times Sq - 42nd St - 7-7","Times Sq - 42nd St - N-Q-R-W"),
    ("Times Sq - 42nd St - 7-7","Times Sq - 42nd St - S"),
    ("Times Sq - 42nd St - N-Q-R-W","Times Sq - 42nd St - S"),
    ("42nd St - Port Authority Bus Term","Times Sq - 42nd St - 1-2-3"),
    ("42nd St - Port Authority Bus Term","Times Sq - 42nd St - 7-7"),
    ("42nd St - Port Authority Bus Term","Times Sq - 42nd St - N-Q-R-W"),
    ("42nd St - Port Authority Bus Term","Times Sq - 42nd St - S"),
    ("149th St - Grand Concourse - 4","149th St - Grand Concourse - 2-5"),
    #("14th St - 1-2-3","6th Ave"),
    ("14th St - 1-2-3","14th St - F-M"),
    ("Park Pl - 2-3","Chambers St - A-C"),
    ("Park Pl - 2-3","World Trade Center"),
    ("Fulton St - 2-3","Fulton St - 4-5"),
    ("Fulton St - 2-3","Fulton St - A-C"),
    ("Fulton St - 2-3","Fulton St - J-Z"),
    ("Fulton St - 4-5","Fulton St - A-C"),
    ("Fulton St - 4-5","Fulton St - J-Z"),
    ("Fulton St - A-C","Fulton St - J-Z"),
    ("Borough Hall - 2-3","Borough Hall - 4-5"),
    ("Borough Hall - 4-5","Court St"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5","Atlantic Av - Barclay's Center - B-Q"),
    ("Atlantic Av - Barclay's Center - 2-3-4-5","Atlantic Av - Barclay's Center - D-N-Q-R"),
    ("Atlantic Av - Barclay's Center - B-Q","Atlantic Av - Barclay's Center - D-N-Q-R"),
    ("Franklin Ave - 2-3-4-5","Botanic Garden"),
    ("Botanic Garden","Prospect Park")
    ]

In [56]:
print sublines


['1', '2', '3', '4', '5', '6', '7', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'J', 'L', 'M', 'N', 'Q', 'R', 'S', 'W', 'Z']

In [57]:
consublines = [Edges1, Edges2, Edges3, Edges4, Edges5, Edges6, Edges7,
               EdgesA, EdgesB, EdgesC, EdgesD, EdgesE, EdgesF, EdgesG,
               EdgesJ, EdgesL, EdgesM, EdgesN, EdgesQ, EdgesR, EdgesS,
               EdgesW, EdgesZ, Edges4RushHour, Edges5RushHour,
               Edges7RushHour, EdgesTransfers]

In [58]:
G=nx.Graph()
for line in consublines:
    for edge in line:
        G.add_edge(edge[0],edge[1])

In [59]:
stationpos


Out[59]:
{u'103rd St - 1': (-73.96837899960818, 40.799446000334825),
 u'103rd St - 4-6-6': (-73.94747800152219, 40.79060000008452),
 u'103rd St - A-B-C': (-73.96137008267617, 40.796060739904526),
 u'103rd St - Corona Plaza': (-73.86269999830412, 40.749865000555545),
 u'104th St': (-73.83768300060997, 40.681711001091195),
 u'104th-102nd Sts': (-73.84443500029684, 40.69516599823373),
 u'110th St': (-73.94424999687163, 40.795020000113105),
 u'111th St - 7': (-73.85533399834884, 40.75172999941711),
 u'111th St - A-S': (-73.83216299845388, 40.68433100001238),
 u'111th St - J': (-73.83679338454697, 40.697114810696476),
 u'116th St - 2-3': (-73.94962500096905, 40.802097999133004),
 u'116th St - 4-6-6': (-73.9416169983714, 40.7986290002001),
 u'116th St - A-B-C': (-73.95479778057312, 40.80505813344211),
 u'116th St - Columbia University': (-73.96410999757751, 40.807722001230864),
 u'121st St': (-73.82834900017954, 40.700481998515315),
 u'125th St - 1': (-73.95837200097044, 40.815580999978934),
 u'125th St - 2-3': (-73.94549500011411, 40.807753999182815),
 u'125th St - 4-5-6-6': (-73.93759400055725, 40.804138000587244),
 u'125th St - A-B-C-D': (-73.95224799734774, 40.811071672994565),
 u'135th St - 2-3': (-73.94077000106708, 40.8142290003391),
 u'135th St - A-B-C': (-73.94753480879213, 40.817905559212676),
 u'137th St - City College': (-73.95367600087873, 40.82200799968475),
 u'138th St - Grand Concourse': (-73.92984899935611, 40.81322399958908),
 u'145th St - 1': (-73.95035999879713, 40.82655099962194),
 u'145th St - 3': (-73.93624499873299, 40.82042099969279),
 u'145th St - A-B-C-D': (-73.94408792823116, 40.824766360871905),
 u'149th St - Grand Concourse - 2-5': (-73.92672247438611, 40.81833014409742),
 u'149th St - Grand Concourse - 4': (-73.9273847542618, 40.81830344372315),
 u'14th St - 1-2-3': (-74.00020100063497, 40.737825999728116),
 u'14th St - A-C-E': (-74.00168999937027, 40.740893000193296),
 u'14th St - F-M': (-73.99620899921355, 40.73822799969515),
 u'155th St - A-C': (-73.94151400082208, 40.83051799929251),
 u'155th St - B-D': (-73.93820899811622, 40.8301349999812),
 u'157th St': (-73.94488999901047, 40.8340410001399),
 u'15th St - Prospect Park': (-73.97973580592873, 40.66003568810021),
 u'161st St - Yankee Stadium - 4': (-73.92569199505733, 40.82823032742169),
 u'161st St - Yankee Stadium - B-D': (-73.92565099775477, 40.827904998845845),
 u'163rd St - Amsterdam Av': (-73.93989200188344, 40.83601299923096),
 u'167th St - 4': (-73.92139999784426, 40.83553699933672),
 u'167th St - B-D': (-73.91843200082253, 40.83376899862797),
 u'168th St - 1': (-73.94013299907257, 40.840555999148535),
 u'168th St - A-C': (-73.93956099985425, 40.84071899990795),
 u'169th St': (-73.79347419927721, 40.710517502784),
 u'170th St - 4': (-73.91779099745928, 40.84007499993004),
 u'170th St - B-D': (-73.91339999846983, 40.83930599964156),
 u'174th St': (-73.88769359812888, 40.837195550170605),
 u'174th-175th Sts': (-73.91013600050078, 40.84589999983414),
 u'175th St': (-73.93970399761596, 40.84739100072403),
 u'176th St': (-73.91179399884471, 40.8484800012369),
 u'181st St - 1': (-73.9335959996056, 40.84950499974065),
 u'181st St - A': (-73.93796900205011, 40.851694999744616),
 u'182nd-183rd Sts': (-73.90074099998965, 40.85609299881864),
 u'183rd St': (-73.90387900151532, 40.85840700040842),
 u'18th Ave - D': (-74.00159259239406, 40.60773573171741),
 u'18th Ave - F': (-73.97697099965796, 40.62975466638584),
 u'18th Ave - N': (-73.99045399865993, 40.620686997680025),
 u'18th St': (-73.99787100060406, 40.741039999802105),
 u'190th St': (-73.93417999964333, 40.85902199892482),
 u'191st St': (-73.92941199742039, 40.85522500175836),
 u'207th St': (-73.91881900132312, 40.864614000525854),
 u'20th Ave - D': (-73.99817432157568, 40.60467699816932),
 u'20th Ave - N': (-73.98452199846113, 40.617108999866005),
 u'215th St': (-73.91527899954356, 40.86944399946045),
 u'219th St': (-73.8625097078866, 40.883887974625274),
 u'21st St': (-73.9495999997552, 40.7441286664954),
 u'21st St - Queensbridge': (-73.94193761457447, 40.75373927087553),
 u'225th St': (-73.86021461772737, 40.88802825863786),
 u'231st St': (-73.90483400107873, 40.87885599817935),
 u'233rd St': (-73.85736239521543, 40.89314324138378),
 u'238th St': (-73.90087000018522, 40.88466700064975),
 u'23rd St - 1-2': (-73.9956570016487, 40.74408099989751),
 u'23rd St - 4-6-6': (-73.98659900207888, 40.739864000474604),
 u'23rd St - A-C-E': (-73.99804100117201, 40.74590599939995),
 u'23rd St - F-M': (-73.99276500471389, 40.742954317826005),
 u'23rd St - N-Q-R-W': (-73.98934400102907, 40.74130266729),
 u'25th Ave': (-73.98682900011477, 40.59770366695856),
 u'25th St': (-73.99809099974297, 40.66039666692321),
 u'28th St - 1-2': (-73.99336500134324, 40.74721499918219),
 u'28th St - 4-6-6': (-73.98426400110407, 40.743069999259035),
 u'28th St - N-Q-R-W': (-73.98869800128737, 40.74545399979951),
 u'30th Ave': (-73.9214790001739, 40.76677866673298),
 u'33rd St - 4-6-6': (-73.98207600148947, 40.74608099909145),
 u'33rd St - 7': (-73.93099699953838, 40.74458699983993),
 u'34th St - Hudson Yards': (-74.00219709442206, 40.75544635961596),
 u'34th St - Penn Station - 1-2-3': (-73.99105699913983, 40.75037300003949),
 u'34th St - Penn Station - A-C-E': (-73.99339099970578, 40.752287000775894),
 u'36th Ave': (-73.929861999118, 40.7564420005104),
 u'36th St - D-N-R': (-74.00354899951809, 40.65514366633887),
 u'36th St - E-M-R': (-73.92901818461539, 40.75196004401078),
 u'39th Ave': (-73.93285137679598, 40.75276306140845),
 u'3rd Ave - 138th St': (-73.92613800014134, 40.81047600117261),
 u'3rd Ave - 149th St': (-73.91779152760981, 40.816029252510006),
 u'40th St': (-73.9240159984882, 40.74378100149132),
 u'42nd St - Bryant Pk': (-73.98459099904711, 40.754184001312545),
 u'42nd St - Port Authority Bus Term': (-73.98973500085859,
  40.757307998551504),
 u'45th St': (-74.01000600074939, 40.648938666612814),
 u'46th St - 7': (-73.91843500103973, 40.74313200060382),
 u'46th St - E-M-R': (-73.91352174995538, 40.756316952608096),
 u'47th-50th Sts - Rockefeller Ctr': (-73.98133100227702, 40.75864100159815),
 u'49th St': (-73.98420956591096, 40.759801973870694),
 u'4th Av - 9th St - D-N-R': (-73.98830199974512, 40.670846666842756),
 u'4th Av - 9th St - F-G': (-73.98977899938897, 40.67027166728493),
 u'50th St - 1-2': (-73.98384899986625, 40.76172799961419),
 u'50th St - A-C-E': (-73.98598400026407, 40.76245599925997),
 u'50th St - D': (-73.9946587805514, 40.636260890961395),
 u'51st St': (-73.97192000069982, 40.75710699989316),
 u'52nd St': (-73.91254899891254, 40.744149001021576),
 u'53rd St': (-74.01403399986317, 40.64506866735981),
 u'55th St': (-73.99534882595742, 40.63147876093745),
 u'57th St - F': (-73.97736800085171, 40.76408500081713),
 u'57th St - N-Q-R-W': (-73.98072973372128, 40.76456552501829),
 u'59th St': (-74.01788099953987, 40.6413616662838),
 u'59th St - Columbus Circle - 1-2': (-73.98192900232715, 40.76824700063689),
 u'59th St - Columbus Circle - A-B-C-D': (-73.98164872301398,
  40.768249531776064),
 u'5th Ave - 53rd St': (-73.9752485052734, 40.76008683231326),
 u'5th Ave - 59th St': (-73.97334700047045, 40.764810999755284),
 u'5th Ave - Bryant Pk': (-73.98196299856706, 40.75382100064824),
 u'62nd St': (-73.99685724994863, 40.626224462922195),
 u'63rd Dr - Rego Park': (-73.86161820097203, 40.729763972422425),
 u'65th St': (-73.8987883783301, 40.74971952935675),
 u'66th St - Lincoln Ctr': (-73.98220899995783, 40.77344000052039),
 u'67th Ave': (-73.85286048434907, 40.726505475813006),
 u'68th St - Hunter College': (-73.96387000158042, 40.76814100049679),
 u'69th St': (-73.8964029993185, 40.746324999410284),
 u'71st St': (-73.99884094850685, 40.61925870977273),
 u'72nd St - 1-2-3': (-73.98197000159583, 40.77845300068614),
 u'72nd St - A-B-C': (-73.976336575218, 40.77551939729258),
 u'72nd St - Q': (-73.95836178682246, 40.76880251014895),
 u'74th St - Broadway': (-73.8912051289911, 40.746867573829114),
 u'75th Ave': (-73.83692369387158, 40.71804465348743),
 u'75th St - Eldert Ln': (-73.86728799944963, 40.691290001246735),
 u'77th St - 4-6-6': (-73.95987399886047, 40.77362000074615),
 u'77th St - R': (-74.0255099996266, 40.629741666886915),
 u'79th St - 1-2': (-73.97991700056134, 40.78393399959032),
 u'79th St - D': (-74.00058287431507, 40.61315892569516),
 u'7th Ave - B-D-E': (-73.98169782344476, 40.76297015245628),
 u'7th Ave - B-Q': (-73.97285279191024, 40.67710217983294),
 u'7th Ave - F-G': (-73.98025117900944, 40.66624469001985),
 u'80th St': (-73.85899200206335, 40.67937100115432),
 u'81st St': (-73.97209794937208, 40.78134608418206),
 u'82nd St - Jackson Hts': (-73.88369700071884, 40.747658999559135),
 u'85th St - Forest Pky': (-73.86008700006875, 40.69242699966103),
 u'86th St - 1-2': (-73.97621799859327, 40.78864400073892),
 u'86th St - 4-5-6-6': (-73.95558899985132, 40.77949199820952),
 u'86th St - A-B-C': (-73.96882849429672, 40.78582304678557),
 u'86th St - Q': (-73.95177090964917, 40.77786104333163),
 u'86th St - R': (-74.0283979999864, 40.62268666715025),
 u'88th St': (-73.85147000026086, 40.67984300135503),
 u'8th Ave - N': (-74.01151599772157, 40.634970999647166),
 u'8th St - NYU': (-73.99250799849149, 40.73046499853991),
 u'90th St - Elmhurst Av': (-73.87661299986985, 40.74840800060913),
 u'96th St - 1-2-3': (-73.97232299915696, 40.79391900121471),
 u'96th St - 4-6-6': (-73.9510700015425, 40.78567199998607),
 u'96th St - A-B-C': (-73.96460245687166, 40.79161879767014),
 u'96th St - Q': (-73.9470660219183, 40.784236650177654),
 u'9th Ave': (-73.99444874451204, 40.64648407726636),
 u'Alabama Ave': (-73.89852600159652, 40.676998000003756),
 u'Allerton Ave': (-73.86723422851625, 40.86548337793927),
 u'Aqueduct - North Conduit Av': (-73.83405799948723, 40.668234001699815),
 u'Aqueduct Racetrack': (-73.83591899965162, 40.672096999172844),
 u'Astor Pl': (-73.99106999861966, 40.73005400028978),
 u'Astoria - Ditmars Blvd': (-73.9120340001031, 40.775035666523664),
 u'Astoria Blvd': (-73.91809500109238, 40.77003699949086),
 u"Atlantic Av - Barclay's Center - 2-3-4-5": (-73.97754993539385,
  40.68442016526762),
 u"Atlantic Av - Barclay's Center - B-Q": (-73.97678343963167,
  40.684488323453685),
 u"Atlantic Av - Barclay's Center - D-N-Q-R": (-73.97880999956767,
  40.683665667279435),
 u'Atlantic Ave': (-73.9030969995401, 40.67534466640805),
 u'Ave H': (-73.96151793942495, 40.62920837758969),
 u'Ave I': (-73.97606933170925, 40.62501744019143),
 u'Ave J': (-73.96069316246925, 40.625022819915166),
 u'Ave M': (-73.9592431052215, 40.617397744443736),
 u'Ave N': (-73.97404850873143, 40.61435671190883),
 u'Ave P': (-73.97300281528751, 40.608842808949916),
 u'Ave U - F': (-73.97337641974885, 40.59592482551748),
 u'Ave U - N': (-73.97908400099428, 40.597235999920436),
 u'Ave U - Q': (-73.95581122316301, 40.59930895095475),
 u'Ave X': (-73.97426599968905, 40.589449666625285),
 u'Bay 50th St': (-73.98376500045946, 40.58884066651933),
 u'Bay Pky - D': (-73.9936762000529, 40.601950461572315),
 u'Bay Pky - F': (-73.9752569782215, 40.62073162316788),
 u'Bay Pky - N': (-73.98178001069293, 40.61145578989005),
 u'Bay Ridge - 95th St': (-74.03087600085765, 40.61662166725951),
 u'Bay Ridge Ave': (-74.02337699950728, 40.63496666682377),
 u'Baychester Ave': (-73.83859099802153, 40.87866300037311),
 u'Beach 105th St': (-73.82758075034528, 40.58326843810286),
 u'Beach 25th St': (-73.76135299762073, 40.60006600105881),
 u'Beach 36th St': (-73.76817499939688, 40.59539800166876),
 u'Beach 44th St': (-73.77601299999507, 40.59294299908617),
 u'Beach 60th St': (-73.7885219980118, 40.59237400121235),
 u'Beach 67th St': (-73.7969239998421, 40.59092700078133),
 u'Beach 90th St': (-73.81365140419632, 40.58809156457325),
 u'Beach 98th St': (-73.82052058959523, 40.58538569133279),
 u'Bedford - Nostrand Aves': (-73.95352200064022, 40.68962700158444),
 u'Bedford Ave': (-73.95666499806525, 40.71717399858899),
 u'Bedford Park Blvd': (-73.88713799889574, 40.87324399861646),
 u'Bedford Park Blvd - Lehman College': (-73.89006400069478,
  40.87341199980121),
 u'Bergen St - 2-3-4': (-73.97499915116808, 40.68086213682956),
 u'Bergen St - F-G': (-73.99075649573565, 40.68611054725977),
 u'Beverly Rd - 2-5': (-73.94884798381702, 40.64512351894373),
 u'Beverly Rd - Q': (-73.96435779623125, 40.64390459860419),
 u'Bleecker St': (-73.99465900006331, 40.72591466682659),
 u'Borough Hall - 2-3': (-73.98999799960687, 40.693218999611084),
 u'Borough Hall - 4-5': (-73.99015100090539, 40.692403999991036),
 u'Botanic Garden': (-73.95924499945693, 40.670342666584396),
 u'Bowery': (-73.99380690654237, 40.720246883147254),
 u'Bowling Green': (-74.01400799803432, 40.70491399928076),
 u'Briarwood - Van Wyck Blvd': (-73.82069263637443, 40.70916181536946),
 u'Brighton Beach': (-73.96135378598797, 40.577710196642435),
 u'Broad Channel': (-73.81583268782963, 40.60840218069683),
 u'Broad St': (-74.01105599991755, 40.706476001106005),
 u'Broadway - G': (-73.95031225606621, 40.706126576274166),
 u'Broadway - Lafayette St': (-73.99620399876055, 40.725296998738045),
 u'Broadway - N-W': (-73.92582299919906, 40.761431998800546),
 u'Broadway Junction - A-C': (-73.90531600055341, 40.67833366608023),
 u'Broadway Junction - J-Z': (-73.90428999746412, 40.67936600147369),
 u'Broadway Junction - L': (-73.90311757920684, 40.67845624842869),
 u'Bronx Park East': (-73.86835609178098, 40.848768666338934),
 u'Brook Ave': (-73.91923999909432, 40.80756599987699),
 u'Brooklyn Bridge - City Hall': (-74.0041310005885, 40.713064999433136),
 u'Brooklyn College - Flatbush Ave': (-73.94754120734406, 40.63284240700742),
 u'Buhre Ave': (-73.83256900003744, 40.846809998885504),
 u'Burke Ave': (-73.86705361747603, 40.87125880254771),
 u'Burnside Ave': (-73.9076840015997, 40.85345300155693),
 u'Bushwick - Aberdeen': (-73.90526176305106, 40.68286062551184),
 u'Canal St - 1-2': (-74.0062770001748, 40.72285399778783),
 u'Canal St - 4-6-6': (-74.00019299927328, 40.71880300107709),
 u'Canal St - Holland Tunnel': (-74.0052290023424, 40.72082400007119),
 u'Canal St - J-Z': (-73.99982638545937, 40.71817387697391),
 u'Canal St - N-Q': (-74.00105471306033, 40.718814263587134),
 u'Canal St - R-W': (-74.0018260000577, 40.71946500105898),
 u'Canarsie - Rockaway Pkwy': (-73.90185000017287, 40.64665366739528),
 u'Carroll St': (-73.99494697998841, 40.68027335170176),
 u'Castle Hill Ave': (-73.85122199961472, 40.83425499825462),
 u'Cathedral Pkwy (110th St) - 1': (-73.9668470005456, 40.80396699961484),
 u'Cathedral Pkwy (110th St) - A-B-C': (-73.95806670661364,
  40.800581558114956),
 u'Central Ave': (-73.92724299902838, 40.69787300011831),
 u'Central Park North (110th St)': (-73.95182200176913, 40.79907499977324),
 u'Chambers St - 1-2-3': (-74.00926600170112, 40.71547800011327),
 u'Chambers St - A-C': (-74.00858473570133, 40.714111000774025),
 u'Chambers St - J-Z': (-74.00340673031336, 40.71323378962671),
 u'Chauncey St': (-73.91038357033376, 40.68285130087804),
 u'Christopher St - Sheridan Sq': (-74.00290599855235, 40.73342200104225),
 u'Church Ave - 2-5': (-73.94945514035334, 40.6508606878022),
 u'Church Ave - B-Q': (-73.96288246192114, 40.65049324646484),
 u'Church Ave - F-G': (-73.97972116229084, 40.64427200012998),
 u'City Hall': (-74.00698581780337, 40.71327233111697),
 u'Clark St': (-73.99308599821961, 40.69746599996469),
 u'Classon Ave': (-73.95999000137212, 40.68888900026455),
 u'Cleveland St': (-73.8851940021643, 40.679777998961164),
 u'Clinton - Washington Aves - A-C': (-73.96583799857275, 40.68326299912644),
 u'Clinton - Washington Aves - G': (-73.9667959986695, 40.68809400106055),
 u'Coney Island - Stillwell Av': (-73.9812359981396, 40.57728100006751),
 u'Cortelyou Rd': (-73.96379005505493, 40.6409401651401),
 u'Cortlandt St - 1': (-74.01218800112292, 40.7118350008202),
 u'Cortlandt St - R-W': (-74.01113196473266, 40.7105129841524),
 u'Court Sq': (-73.94526400039679, 40.74702299889643),
 u'Court Sq - 23rd St': (-73.94605470266329, 40.747768121414325),
 u'Court St': (-73.99181830901125, 40.694196480776995),
 u'Crescent St': (-73.87392925215778, 40.68315265707736),
 u'Crown Hts - Utica Ave': (-73.93293256081851, 40.66897831107809),
 u'Cypress Ave': (-73.91404199994753, 40.8053680007636),
 u'Cypress Hills': (-73.87332199882995, 40.689616000838754),
 u'DeKalb Ave - B-D-N-Q-R': (-73.98177094440949, 40.690648119969794),
 u'DeKalb Ave - L': (-73.91823200219723, 40.70369299961644),
 u'Delancey St - Essex St - F': (-73.98807806807719, 40.71868074219453),
 u'Delancey St - Essex St - J-M-Z': (-73.98740940202974, 40.71830605618619),
 u'Ditmas Ave': (-73.97817199965161, 40.63611866666291),
 u'Dyckman St - 1': (-73.92553600006474, 40.86053100138796),
 u'Dyckman St - A': (-73.92727099960726, 40.865490998968916),
 u'E 105th St': (-73.89954769388724, 40.65046878544699),
 u"E 143rd St - St Mary's St": (-73.90765699936489, 40.80871900090143),
 u'E 149th St': (-73.90409799875945, 40.81211799827203),
 u'E 180th St': (-73.87334609510884, 40.8418630412186),
 u'East Broadway': (-73.99017700122197, 40.713855001020406),
 u'Eastchester - Dyre Ave': (-73.8308340021742, 40.88829999901007),
 u'Eastern Pkwy - Bklyn Museum': (-73.96422203748425, 40.67203223545925),
 u'Elder Ave': (-73.87915899874777, 40.82858400108929),
 u'Elmhurst Ave': (-73.8820347465864, 40.74237007972169),
 u'Euclid Ave': (-73.87210600099675, 40.675376998239365),
 u'Far Rockaway - Mott Ave': (-73.75540499924732, 40.603995001687544),
 u'Flushing - Main St': (-73.83003000262508, 40.75959999915012),
 u'Flushing Ave - G': (-73.9502340010257, 40.70037666622154),
 u'Flushing Ave - J-M': (-73.94137734838365, 40.70040440298112),
 u'Fordham Rd - 4': (-73.90103399921699, 40.86280299988937),
 u'Fordham Rd - B-D': (-73.89774900102401, 40.861295998683495),
 u'Forest Ave': (-73.90307500005954, 40.70441200087814),
 u'Forest Hills - 71st Av': (-73.84451672012669, 40.72159430953587),
 u'Franklin Ave - 2-3-4-5': (-73.9580997367769, 40.67076515344894),
 u'Franklin Ave - A-C': (-73.95684800014614, 40.68137966658742),
 u'Franklin Ave - Fulton St': (-73.95582700110425, 40.68059566598263),
 u'Franklin St': (-74.00688600277107, 40.719318001302135),
 u'Freeman St': (-73.89175225349464, 40.829987446384116),
 u'Fresh Pond Rd': (-73.8958980017196, 40.70622599823048),
 u'Ft Hamilton Pkwy - D': (-73.9942022375285, 40.640912711444656),
 u'Ft Hamilton Pkwy - F-G': (-73.97577599917474, 40.65078166803418),
 u'Ft Hamilton Pkwy - N': (-74.00535100046275, 40.63138566722445),
 u'Fulton St - 2-3': (-74.00657099970202, 40.70941599925865),
 u'Fulton St - 4-5': (-74.00950899856461, 40.710367998822136),
 u'Fulton St - A-C': (-74.00762309323994, 40.71016216530185),
 u'Fulton St - G': (-73.97537499833149, 40.68711899950771),
 u'Fulton St - J-Z': (-74.00793800110387, 40.71002266658424),
 u'Gates Ave': (-73.92215600150752, 40.689583999013905),
 u'Graham Ave': (-73.94394399869037, 40.714575998363635),
 u'Grand Army Plaza': (-73.9709563319228, 40.6752946951032),
 u'Grand Ave - Newtown': (-73.87722085669182, 40.736813418197144),
 u'Grand Central - 42nd St - 4-5-6-6': (-73.9767132992584, 40.75180742981634),
 u'Grand Central - 42nd St - 7-7': (-73.97604100111508, 40.751431000286864),
 u'Grand Central - 42nd St - S': (-73.97918899989101, 40.75276866674217),
 u'Grand St - B-D': (-73.99375299913589, 40.71826699954992),
 u'Grand St - L': (-73.94049699874644, 40.71157600064823),
 u'Grant Ave': (-73.86504999877702, 40.67704400054478),
 u'Gravesend - 86th St': (-73.97818899936274, 40.59246500088859),
 u'Greenpoint Ave': (-73.95442500146235, 40.73126699971465),
 u'Gun Hill Rd - 2-5': (-73.86613410538703, 40.877839385172024),
 u'Gun Hill Rd - 5': (-73.84638400151765, 40.86952599962676),
 u'Halsey St - J': (-73.9166388842194, 40.686415270704344),
 u'Halsey St - L': (-73.90393400118631, 40.69551800114878),
 u'Harlem - 148 St': (-73.93647000005559, 40.82388000080457),
 u'Herald Sq - 34th St - B-D-F-M': (-73.98777189072918, 40.74978939990011),
 u'Herald Sq - 34th St - N-Q-R-W': (-73.9879368338264, 40.74964456009442),
 u'Hewes St': (-73.95348800038457, 40.706889998054),
 u'High St': (-73.99053100065458, 40.69933699977884),
 u'Houston St': (-74.00536700180581, 40.728251000730204),
 u'Howard Beach - JFK Airport': (-73.83030100071032, 40.66047600004959),
 u'Hoyt - Schermerhorn Sts': (-73.98503624034139, 40.68840847580642),
 u'Hoyt St': (-73.98506379575646, 40.69054418535472),
 u'Hunters Point Ave': (-73.9489160009391, 40.74221599986316),
 u'Hunts Point Ave': (-73.89054900017344, 40.82094799852307),
 u'Intervale Ave': (-73.89661738461646, 40.822142131170786),
 u'Inwood - 207th St': (-73.91989900100465, 40.86807199999737),
 u'Jackson Ave': (-73.9077019387083, 40.81643746686396),
 u'Jackson Hts - Roosevelt Av': (-73.89129866519697, 40.74653969115889),
 u'Jamaica - 179th St': (-73.78381700176453, 40.712645666744045),
 u'Jamaica - Van Wyck': (-73.81701287135405, 40.70289855287313),
 u'Jamaica Ctr - Parsons / Archer': (-73.80109632298924, 40.70206737621188),
 u'Jay St - MetroTech - A-C-F': (-73.98721815267317, 40.692470636847084),
 u'Jay St - MetroTech - N-R': (-73.98605667854612, 40.69225539645323),
 u'Jefferson St': (-73.9229130000312, 40.706606665988716),
 u'Junction Blvd': (-73.86952700103515, 40.74914499948836),
 u'Junius St': (-73.90244864183562, 40.66358900181724),
 u'Kew Gardens - Union Tpke': (-73.8303702709878, 40.714034819571026),
 u'Kings Hwy - B-Q': (-73.95760873538083, 40.608638645396006),
 u'Kings Hwy - F': (-73.9723553085244, 40.603258405128265),
 u'Kings Hwy - N': (-73.98037300229343, 40.60405899980493),
 u'Kingsbridge Rd - 4': (-73.89717400101743, 40.867760000885795),
 u'Kingsbridge Rd - B-D': (-73.8935090000331, 40.86697799999945),
 u'Kingston - Throop Aves': (-73.94085899871263, 40.67991899941601),
 u'Kingston Ave': (-73.94215978392963, 40.66948144864978),
 u'Knickerbocker Ave': (-73.91972000188625, 40.69866000123805),
 u'Kosciuszko St': (-73.92850899927413, 40.69317200129202),
 u'Lafayette Ave': (-73.97394599849406, 40.68611300020567),
 u'Lexington Ave - 53rd St': (-73.96907237490204, 40.75746830782865),
 u'Lexington Ave - 59th St - 4-5-6-6': (-73.9679670004732, 40.762526000304575),
 u'Lexington Ave - 59th St - N-R-W': (-73.96737501711436, 40.762708855394564),
 u'Lexington Ave - 63rd St': (-73.96608964413245, 40.76461809442373),
 u'Liberty Ave': (-73.89654800103929, 40.67454199987086),
 u'Livonia Ave': (-73.90056237226057, 40.66405727094644),
 u'Long Island City - Court Sq': (-73.94381559597835, 40.74630503357145),
 u'Longwood Ave': (-73.89643499897414, 40.816103999972405),
 u'Lorimer St - J-M': (-73.94735499884204, 40.703844000042096),
 u'Lorimer St - L': (-73.95024799996972, 40.71407200064717),
 u'Lower East Side - 2nd Ave': (-73.98993800003434, 40.72340166574911),
 u'Marble Hill - 225th St': (-73.90983099923551, 40.87456099941789),
 u'Marcy Ave': (-73.95783200075729, 40.708383000017925),
 u'Metropolitan Ave': (-73.9514239994525, 40.71277400073426),
 u'Mets - Willets Point': (-73.8456249984179, 40.75462199881262),
 u'Middle Village - Metropolitan Ave': (-73.88957722978091,
  40.711431305058255),
 u'Middletown Rd': (-73.83632199755944, 40.84386300128381),
 u'Montrose Ave': (-73.93979284713505, 40.70739106438455),
 u'Morgan Ave': (-73.93314700024209, 40.70615166680729),
 u'Morris Park': (-73.86049500117254, 40.85436399966426),
 u'Morrison Av - Soundview': (-73.87451599929486, 40.82952100156747),
 u'Mosholu Pkwy': (-73.88465499988732, 40.87974999947229),
 u'Mt Eden Ave': (-73.9146849986034, 40.84443400092679),
 u'Myrtle - Wyckoff Aves - L': (-73.9109757182647, 40.699471062427136),
 u'Myrtle - Wyckoff Aves - M': (-73.91217899939602, 40.69945400090837),
 u'Myrtle Ave': (-73.9356230012996, 40.6971950005145),
 u'Myrtle-Willoughby Aves': (-73.94906699890156, 40.69461899903765),
 u'Nassau Ave': (-73.95118300016523, 40.724479997808274),
 u'Neck Rd': (-73.95507827493762, 40.59532169111695),
 u'Neptune Ave': (-73.97459272818807, 40.580738758491464),
 u'Nereid Ave (238 St)': (-73.8543153107622, 40.898286515575286),
 u'Nevins St': (-73.98040679874578, 40.68831058019022),
 u'New Lots Ave - 3-4': (-73.88411070800329, 40.6663149325969),
 u'New Lots Ave - L': (-73.89927796057142, 40.65891477368527),
 u'New Utrecht Ave': (-73.99635300025969, 40.62484166725887),
 u'Newkirk Ave - 2-5': (-73.94829990822407, 40.63999124275311),
 u'Newkirk Ave - B-Q': (-73.96269486837261, 40.63514193733789),
 u'Northern Blvd': (-73.90606508052358, 40.752824829236076),
 u'Norwood - 205th St': (-73.87885499918691, 40.87481100011182),
 u'Norwood Ave': (-73.87962599910783, 40.68152000045683),
 u'Nostrand Ave - 3-4': (-73.9504262489579, 40.66993815093054),
 u'Nostrand Ave - A-C': (-73.95042600099683, 40.68043800006226),
 u'Ocean Pkwy': (-73.96850099975177, 40.57631166708091),
 u'Ozone Park - Lefferts Blvd': (-73.82579799906613, 40.68595099878361),
 u'Park Pl - 2-3': (-74.00881099997359, 40.713050999077694),
 u'Park Pl - S': (-73.95762400074634, 40.67477166685263),
 u'Parkchester': (-73.86081600108396, 40.83322599927859),
 u'Parkside Ave': (-73.96145343987648, 40.65507304163716),
 u'Parsons Blvd': (-73.80328900021885, 40.707571999615695),
 u'Pelham Bay Park': (-73.82812100059289, 40.85246199951662),
 u'Pelham Pkwy - 2-5': (-73.86748067850041, 40.8571924091606),
 u'Pelham Pkwy - 5': (-73.85535900043564, 40.858984999820116),
 u'Pennsylvania Ave': (-73.89488591154061, 40.66471445143568),
 u'President St': (-73.95058920022207, 40.667883603536815),
 u'Prince St': (-73.99770200045987, 40.72432866597571),
 u'Prospect Ave - 2-5': (-73.90177778730917, 40.81948726483844),
 u'Prospect Ave - D-N-R': (-73.99287200067424, 40.66541366712979),
 u'Prospect Park': (-73.96203130426609, 40.6616334551018),
 u'Queens Plz': (-73.93713823965695, 40.74891771986323),
 u'Queensboro Plz': (-73.9401635351909, 40.750635651014804),
 u'Ralph Ave': (-73.92078599933306, 40.678822000873375),
 u'Rector St - 1': (-74.01378300119742, 40.707512999521775),
 u'Rector St - R-W': (-74.01297456253795, 40.707744756294474),
 u'Rockaway Ave - 3-4': (-73.90895833584449, 40.66261748815223),
 u'Rockaway Ave - A-C': (-73.91194599726617, 40.678339999883505),
 u'Rockaway Blvd': (-73.8438529979573, 40.680428999588415),
 u'Rockaway Park - Beach 116 St': (-73.83559008701239, 40.580955865573515),
 u'Roosevelt Island - Main St': (-73.95323499978866, 40.75917199967108),
 u'Saratoga Ave': (-73.91633025007947, 40.6615297898075),
 u'Seneca Ave': (-73.90758199885423, 40.70291899894902),
 u'Sheepshead Bay': (-73.95405791257907, 40.58654754707536),
 u'Shepherd Ave': (-73.88074999747269, 40.6741300014559),
 u'Simpson St': (-73.89306639507903, 40.823976841237396),
 u'Smith - 9th Sts': (-73.99589172790934, 40.67364106090412),
 u'South Ferry': (-74.01316895919258, 40.701730507574474),
 u'Spring St - 4-6-6': (-73.99714100006673, 40.72230099999366),
 u'Spring St - A-C-E': (-74.00373899843763, 40.72622700129312),
 u'St Lawrence Ave': (-73.86761799923673, 40.8315090005233),
 u'Steinway St': (-73.9205264716827, 40.75698735912575),
 u'Sterling St': (-73.95072891124937, 40.6627729934283),
 u'Sutphin Blvd': (-73.81083299897232, 40.70541799906764),
 u'Sutphin Blvd - Archer Av': (-73.80800471963833, 40.700382424235),
 u'Sutter Ave': (-73.9019160004208, 40.66914500061398),
 u'Sutter Ave - Rutland Road': (-73.92252118536001, 40.66476678877493),
 u'Times Sq - 42nd St - 1-2-3': (-73.98749500051885, 40.75528999995681),
 u'Times Sq - 42nd St - 7-7': (-73.98769099825152, 40.755477001982506),
 u'Times Sq - 42nd St - N-Q-R-W': (-73.98676800153976, 40.75461199851542),
 u'Times Sq - 42nd St - S': (-73.98622899953202, 40.755983000570076),
 u'Tremont Ave': (-73.90522700122354, 40.850409999510234),
 u'Union Sq - 14th St - 4-5-6-6': (-73.98995099881881, 40.734673000996125),
 u'Union Sq - 14th St - N-Q-R-W': (-73.99053886181645, 40.73587226699812),
 u'Union St': (-73.98310999909673, 40.67731566735096),
 u'Utica Ave': (-73.93072899914027, 40.67936399950546),
 u'Van Cortlandt Park - 242nd St': (-73.89858300049647, 40.88924800011476),
 u'Van Siclen Ave - 3-4': (-73.88940491730106, 40.665517963059635),
 u'Van Siclen Ave - A-C': (-73.8903580002471, 40.67270999906104),
 u'Van Siclen Ave - J-Z': (-73.89165772702445, 40.67802821447783),
 u'Vernon Blvd - Jackson Ave': (-73.95358099875249, 40.74262599969749),
 u'W 4th St - Washington Sq (Lower)': (-74.00030814755975, 40.732254493367876),
 u'W 4th St - Washington Sq (Upper)': (-74.00049500225435, 40.73233799774325),
 u'W 8th St - NY Aquarium': (-73.97595787413822, 40.576033818103646),
 u'Wakefield - 241st St': (-73.8506199987954, 40.903125000541245),
 u'Wall St - 2-3': (-74.00909999844257, 40.706820999753376),
 u'Wall St - 4-5': (-74.01186199860112, 40.70755700086603),
 u'West Farms Sq - E Tremont Av': (-73.87996127877184, 40.84020763241799),
 u'Westchester Sq - E Tremont Ave': (-73.84295199925012, 40.839892001013915),
 u'Whitehall St': (-74.0130072374272, 40.703142373599135),
 u'Whitlock Ave': (-73.8862829985325, 40.82652500055904),
 u'Wilson Ave': (-73.90395860491864, 40.68886654246024),
 u'Winthrop St': (-73.95007934590994, 40.65665931376077),
 u'Woodhaven Blvd': (-73.85205199740794, 40.69370399880105),
 u'Woodhaven Blvd - Queens Mall': (-73.86943208612348, 40.73309737380972),
 u'Woodlawn': (-73.87875099990931, 40.886037000253324),
 u'Woodside - 61st St': (-73.90298400173006, 40.745630001138395),
 u'World Trade Center': (-74.00974461517701, 40.71256392680817),
 u'York St': (-73.98688499993673, 40.699742667691574),
 u'Zerega Ave': (-73.8470359987544, 40.836488000608156)}

In [60]:
f, ax = pl.subplots(figsize=(15,12))
pl.axis('off')

nx.draw(G,pos=stationpos,with_labels=False,arrows=True,node_size=15,style='dotted',edge_color='green')
pl.title("NYC Subway Network", size=20)


Out[60]:
<matplotlib.text.Text at 0x20128f60>

In [61]:
nodes = G.nodes()
nodes.sort()

In [62]:
len(G.node)


Out[62]:
467

In [63]:
len(subStations)


Out[63]:
468

In [64]:
listtotest=[]
for i in range(len(G.node)):
    listtotest.append(G.node.items()[i][0])

In [65]:
for i in range(len(subStations)):
    if list(subStations.namemod)[i] in listtotest:
        pass
    else:
        print list(subStations.namemod)[i]


Cortlandt St - 1

nx.closeness_centrality(G, u=None, distance=None)


In [66]:
sum(list(zip(*nx.single_source_shortest_path_length(G,'Ave X').items())[1]))/len(list(zip(*nx.single_source_shortest_path_length(G,'Ave X').items())[1]))


Out[66]:
19

In [67]:
len(list(zip(*nx.single_source_shortest_path_length(G,'Astor Pl').items())[1]))


Out[67]:
467

In [68]:
sum(list(zip(*nx.single_source_shortest_path_length(G,'Astor Pl').items())[1]))/len(list(zip(*nx.single_source_shortest_path_length(G,'Astor Pl').items())[1]))


Out[68]:
9

In [69]:
ConnectivityList = []
for node in subStations.namemod:
    if node!='Cortlandt St - 1':
        ConnectivityList.append(sum(list(zip(*nx.single_source_shortest_path_length(G,node).items())[1]))/float(len(G.node)))
    else:
        ConnectivityList.append(np.nan)
    #print nodeb

In [70]:
subStations['AverageShortestPath'] = ConnectivityList

In [71]:
len(nx.single_source_shortest_path_length(G,'Ave X').items())


Out[71]:
467

In [72]:
ConnectivityList = []
for node in subStations.namemod:
    if node!='Cortlandt St - 1':
        if len(list(zip(*nx.single_source_shortest_path_length(G,node).items())[1])) != 467:
            print 'Error'

In [73]:
subStations.head(3)


Out[73]:
index geometry line name notes objectid url nameduplicated namemod longlat AverageShortestPath
0 0 POINT (-73.99106999861967 40.73005400028978) 4-6-6 Express Astor Pl 4 nights, 6-all times, 6 Express-weekdays AM s... 1 http://web.mta.info/nyct/service/ False Astor Pl (-73.9910699986, 40.7300540003) 9.730193
1 1 POINT (-74.00019299927328 40.71880300107709) 4-6-6 Express Canal St 4 nights, 6-all times, 6 Express-weekdays AM s... 2 http://web.mta.info/nyct/service/ True Canal St - 4-6-6 (-74.0001929993, 40.7188030011) 9.400428
2 2 POINT (-73.98384899986625 40.76172799961419) 1-2 50th St 1-all times, 2-nights 3 http://web.mta.info/nyct/service/ True 50th St - 1-2 (-73.9838489999, 40.7617279996) 10.646681

In [74]:
subStations.AverageShortestPath.max()


Out[74]:
29.436830835117775

In [75]:
subStations.AverageShortestPath.min()


Out[75]:
8.8736616702355455

In [76]:
f, ax = pl.subplots(figsize=(15,12))
pl.axis('off')
tracks.plot(c = 'k', linewidth = .5, ax = ax,  color= 'Blue')
subStations[subStations.AverageShortestPath==subStations.AverageShortestPath.max()].plot(marker='o', markersize=10, linewidth = 4, c='r', ax = ax)
subStations[subStations.AverageShortestPath==subStations.AverageShortestPath.min()].plot(marker='o', markersize=10, linewidth = 4, c='b', ax = ax)
pl.title("NYC Subway Stations", size=20)


Out[76]:
<matplotlib.text.Text at 0x204aa630>

In [77]:
subStations[subStations.AverageShortestPath==subStations.AverageShortestPath.min()]


Out[77]:
index geometry line name notes objectid url nameduplicated namemod longlat AverageShortestPath
377 378 POINT (-73.99053886181645 40.73587226699812) N-Q-R-W Union Sq - 14th St N,Q-all times, R-all times exc nights 379 http://web.mta.info/nyct/service/ True Union Sq - 14th St - N-Q-R-W (-73.9905388618, 40.735872267) 8.873662

In [78]:
subStations[subStations.AverageShortestPath==subStations.AverageShortestPath.max()]


Out[78]:
index geometry line name notes objectid url nameduplicated namemod longlat AverageShortestPath
278 279 POINT (-73.8506199987954 40.90312500054125) 2 Wakefield - 241st St 2-all times 280 http://web.mta.info/nyct/service/ False Wakefield - 241st St (-73.8506199988, 40.9031250005) 29.436831

In [79]:
subStations['ConnectivityScore'] = (29-(subStations.AverageShortestPath-1))

In [80]:
subStations.head(3)


Out[80]:
index geometry line name notes objectid url nameduplicated namemod longlat AverageShortestPath ConnectivityScore
0 0 POINT (-73.99106999861967 40.73005400028978) 4-6-6 Express Astor Pl 4 nights, 6-all times, 6 Express-weekdays AM s... 1 http://web.mta.info/nyct/service/ False Astor Pl (-73.9910699986, 40.7300540003) 9.730193 20.269807
1 1 POINT (-74.00019299927328 40.71880300107709) 4-6-6 Express Canal St 4 nights, 6-all times, 6 Express-weekdays AM s... 2 http://web.mta.info/nyct/service/ True Canal St - 4-6-6 (-74.0001929993, 40.7188030011) 9.400428 20.599572
2 2 POINT (-73.98384899986625 40.76172799961419) 1-2 50th St 1-all times, 2-nights 3 http://web.mta.info/nyct/service/ True 50th St - 1-2 (-73.9838489999, 40.7617279996) 10.646681 19.353319

In [81]:
prj = 'GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]'

In [82]:
subStations.crs


Out[82]:
{'init': 'epsg:4326', 'no_defs': True}

In [83]:
with open('SubwayStationsWithScoresNOLTRAIN.geojson', 'w') as f:
    f.write(subStations.to_json())

In [84]:
subStations = gpd.GeoDataFrame.from_file('SubwayStationsWithScoresNOLTRAIN.geojson')
subStations.head()


Out[84]:
AverageShortestPath ConnectivityScore geometry id index line name nameduplicated namemod notes objectid url
0 9.730193 20.269807 POINT (-73.99106999861967 40.73005400028978) 0 0 4-6-6 Express Astor Pl 0 Astor Pl 4 nights, 6-all times, 6 Express-weekdays AM s... 1 http://web.mta.info/nyct/service/
1 9.400428 20.599572 POINT (-74.00019299927328 40.71880300107709) 1 1 4-6-6 Express Canal St 1 Canal St - 4-6-6 4 nights, 6-all times, 6 Express-weekdays AM s... 2 http://web.mta.info/nyct/service/
2 10.646681 19.353319 POINT (-73.98384899986625 40.76172799961419) 2 2 1-2 50th St 1 50th St - 1-2 1-all times, 2-nights 3 http://web.mta.info/nyct/service/
3 10.910064 19.089936 POINT (-73.97499915116808 40.68086213682956) 3 3 2-3-4 Bergen St 1 Bergen St - 2-3-4 4-nights, 3-all other times, 2-all times 4 http://web.mta.info/nyct/service/
4 16.334047 13.665953 POINT (-73.89488591154061 40.66471445143568) 4 4 3-4 Pennsylvania Ave 0 Pennsylvania Ave 4-nights, 3-all other times 5 http://web.mta.info/nyct/service/

In [85]:
subStations.crs


Out[85]:
{}

In [86]:
subStations.to_file(filename='connectivityNOLTRAIN',driver='ESRI Shapefile',crs_wkt=prj)

Starting Simulation Part


In [87]:
jobs = gpd.GeoDataFrame.from_file('output/jobscentroids.shp')
houses = gpd.GeoDataFrame.from_file('output/housecentroid.shp')
jobs = jobs.ix[[114,166,215,277]]
jobs.reset_index(inplace=True, drop=True)
houses = houses.ix[[154,124,27,100]]
houses.reset_index(inplace=True, drop=True)

Get Walkings distances for origin and destinations


In [88]:
walkingdistance='15'
jobs['buffer']=np.nan
for i in range(len(jobs)):
    url = 'http://matrix.mapzen.com/isochrone?json={"locations":[{"lat":'+str(jobs.ycentroid[i])+',"lon":'+str(jobs.xcentroid[i])+'}],"costing":"pedestrian","contours":[{"time":' + walkingdistance + ',"color":"ff0000"}]}&id=Walk_From_L&api_key='+(os.getenv("MAPZENKEY"))
    response = urllib2.urlopen(url)
    data = response.read().decode('utf-8')
    dataDict = json.loads(data)
    sleep(2.3) 
    jobs.loc[i,'buffer'] = Polygon(dataDict['features'][0]['geometry']['coordinates'])
### avoid being blocked by the MapzenAPI services
Polygon(dataDict['features'][0]['geometry']['coordinates'])


Out[88]:

In [89]:
walkingdistance='15'
houses['buffer']=np.nan
for i in range(len(houses)):
    url = 'http://matrix.mapzen.com/isochrone?json={"locations":[{"lat":'+str(houses.ycentroid[i])+',"lon":'+str(houses.xcentroid[i])+'}],"costing":"pedestrian","contours":[{"time":' + walkingdistance + ',"color":"ff0000"}]}&id=Walk_From_L&api_key='+(os.getenv("MAPZENKEY"))
    response = urllib2.urlopen(url)
    data = response.read().decode('utf-8')
    dataDict = json.loads(data)
    sleep(2.3) 
    houses.loc[i,'buffer'] = Polygon(dataDict['features'][0]['geometry']['coordinates'])
### avoid being blocked by the MapzenAPI services
Polygon(dataDict['features'][0]['geometry']['coordinates'])


Out[89]:

In [90]:
jobs.columns.tolist()
jobs = jobs[[
 #u'HomeAffect',
 #u'JobsAffect',
 #u'Within15mi',
 #u'Within30mi',
 #u'boro_code',
 u'boro_ct_20',
 #u'boro_name',
 #u'cdeligibil',
 u'ct_2010',
 u'ctlabel',
 #'geometry',
 u'id',
 u'ntacode',
 u'ntaname',
 #u'puma',
 #u'shape_area',
 #u'shape_leng',
 u'xcentroid',
 u'ycentroid',
 'buffer'
         ]]

In [91]:
houses.columns.tolist()
houses = houses[[
 #u'HomeAffect',
 #u'JobsAffect',
 #u'Within15mi',
 #u'Within30mi',
 #u'boro_code',
 u'boro_ct_20',
 #u'boro_name',
 #u'cdeligibil',
 u'ct_2010',
 u'ctlabel',
 #'geometry',
 u'id',
 u'ntacode',
 u'ntaname',
 #u'puma',
 #u'shape_area',
 #u'shape_leng',
 u'xcentroid',
 u'ycentroid',
 'buffer'
         ]]

In [92]:
jobs = jobs.set_geometry('buffer')
houses = houses.set_geometry('buffer')

In [93]:
houses.head()


Out[93]:
boro_ct_20 ct_2010 ctlabel id ntacode ntaname xcentroid ycentroid buffer
0 3051900 051900 519 2039 BK73 North Side-South Side -73.955158 40.715715 POLYGON ((-73.95008900000001 40.725788, -73.94...
1 3109800 109800 1098 1684 BK82 East New York -73.901645 40.652663 POLYGON ((-73.89949799999999 40.664806, -73.89...
2 3057100 057100 571 211 BK76 Greenpoint -73.947619 40.724784 POLYGON ((-73.952522 40.736881, -73.950844 40....
3 3049300 049300 493 1238 BK78 Bushwick South -73.941354 40.707807 POLYGON ((-73.939919 40.719234, -73.939453 40....

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [94]:
f, ax = pl.subplots(figsize=(55,55))
for polygon in un:
    patch = PolygonPatch(polygon, alpha=0.5, zorder=2)
    ax.add_patch(patch)
    #sns.jointplot(x="longitude", y="latitude", data=gdf, kind="kde", size=24,ax=ax)
nx.draw(G,pos=stationpos,with_labels=False,node_size=85,style='dotted',edge_color='green', width=8)
pl.axis('off')
pl.title("NYC Subway Stations", size=80)
pl.xlim(-74.030876, -73.755405)
pl.ylim(40.576034, 40.903125)
    #count=0
for i in range(len(houses)):
    #i=3
    pl.plot(houses.xcentroid[i], houses.ycentroid[i], marker='o', markersize=20, color="purple", linewidth = 4,label='Origin')
    pl.plot(jobs.xcentroid[i], jobs.ycentroid[i], marker='o', markersize=20, color="g", linewidth = 4,label='Origin')
jobs.plot(ax=ax)
houses.plot(ax=ax)


Out[94]:
<matplotlib.axes._subplots.AxesSubplot at 0x2a4e7c88>

Stations within 15 minutes Walking distance


In [95]:
for buf in houses['buffer']:
    mask1=[]
    for station in subStations.geometry:
        mask1.append(station.within(buf))

for buf in jobs['buffer']:
    mask2=[]
    for station in subStations.geometry:
        mask2.append(station.within(buf))

In [96]:
houses['buffer'][0]


Out[96]:

In [ ]:
import imageio
from PIL import Image
for i in range(len(houses)):
    x=len(subStations)
    mask1=[]
    
    for station in subStations.geometry:
        mask1.append(station.within(houses['buffer'][i]))
    print 'Hola'
    for j in range(len(jobs)):
        mask2=[]
        
        for station in subStations.geometry:
            mask2.append(station.within(jobs['buffer'][j]))
        #print houses['ntaname'][i],jobs['ntaname'][i]
        print i,len(mask1), j,len(mask2)
        y=len(subStations)
        for begining in subStations[mask1].namemod:
            for ending in subStations[mask2].namemod:
                path = nx.shortest_path(G, source=begining, target=ending)
                #print len(path)
                if y>len(path):
                    y=len(path)
                    selected = path
        steps = selected
        print steps, len(steps)
        print i,len(mask1), j,len(mask2)

        f, ax = pl.subplots(figsize=(45,45))
        for polygon in un:
            patch = PolygonPatch(polygon, alpha=0.5, zorder=2)
            ax.add_patch(patch)
            #sns.jointplot(x="longitude", y="latitude", data=gdf, kind="kde", size=24,ax=ax)
        nx.draw(G,pos=stationpos,with_labels=False,node_size=85,style='dotted',edge_color='green', width=8)
        pl.axis('off')
        pl.title("NYC Subway Network After L-Train Partial Closure", size=80)
        pl.xlim(-74.030876, -73.755405)
        pl.ylim(40.576034, 40.903125)
        count=0
        filname = []
            #start
        pl.plot(houses.xcentroid[i], houses.ycentroid[i], marker='o', markersize=55, color="purple", linewidth = 4,label='Origin')
            #end
        pl.plot(jobs.xcentroid[j], jobs.ycentroid[j], marker='o', markersize=55, color="g", linewidth = 4,label='Destination')

        pl.legend(loc=2,prop={'size':63})

            #subStations[subStations.namemod==steps[-1]].plot(marker='o', markersize=55, linewidth = 4, c='g', ax = ax)
        counter=0
        for step in steps:
            if counter==0:
                #sdfg
                name = str(i) + '-' + str(j)+'startset'+'.png'
                filname.append(name)
                pl.savefig('Data/'+ name)
                img = Image.open('Data/'+ name)
                img2 = img.crop((400, 200, 2900, 2850))
                img2 = img2.save('Data/' + name)

                pl.plot(houses.xcentroid[i], houses.ycentroid[i], marker='o', markersize=35, linewidth = 4, c='c')
                name = str(i) + '-' + str(j)+'start'+'.png'
                filname.append(name)
                pl.savefig('Data/'+ name)
                img = Image.open('Data/'+ name)
                img2 = img.crop((400, 200, 2900, 2850))
                img2 = img2.save('Data/' + name)

                
            subStations[subStations.namemod==step].plot(marker='o', markersize=35, linewidth = 4, c='c', ax = ax)
            name = str(i) + '-' + str(j)+'foo'+str(count)+'.png'
            filname.append(name)
            pl.savefig('Data/'+ name)
            img = Image.open('Data/'+ name)
            img2 = img.crop((400, 200, 2900, 2850))
            img2 = img2.save('Data/' + name)
            
            if counter==len(steps)-1:
                pl.plot(jobs.xcentroid[j], jobs.ycentroid[j], marker='o', markersize=35, linewidth = 4, c='c')
                name = str(i) + '-' + str(j)+'end'+'.png'
                filname.append(name)
                pl.savefig('Data/'+ name)
                img = Image.open('Data/'+ name)
                img2 = img.crop((400, 200, 2900, 2850))
                img2 = img2.save('Data/' + name)
                
            count+=1
            counter+=1
        with imageio.get_writer('Data/'+ str(i)+ '-' + str(j) +'test.gif', mode='I') as writer:
            for fil in filname:
                image = imageio.imread('Data/'+fil)
                writer.append_data(image)


Hola
0 468 0 468
[u'Marcy Ave', 'Delancey St - Essex St - J-M-Z', 'Bowery', 'Canal St - J-Z', 'Chambers St - J-Z', u'Fulton St - J-Z'] 6
0 468 0 468
0 468 1 468
[u'Marcy Ave', 'Delancey St - Essex St - J-M-Z', u'Broadway - Lafayette St'] 3
0 468 1 468
0 468 2 468
[u'Marcy Ave', 'Delancey St - Essex St - J-M-Z', 'Broadway - Lafayette St', 'W 4th St - Washington Sq (Lower)', u'Herald Sq - 34th St - B-D-F-M'] 5
0 468 2 468

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: